五、.NET Framework 2.0/C# 2.0语法知识考察,C#高级语法考察(泛型及泛型技巧、匿名方法及其技巧)
1、看函数代码,然后回答问题(难度系数80%):
public static T[] SomeMethod<T>( T value, int size )
{
T[] arr = new T[size];
for ( int i = 0; i < size, i++ )
arr[i] = value;
return arr;
}
试阐述这个函数的作用。
请问,这样调用这个函数有没有问题,如有问题,有何问题?
long[] result = SomeMethod( 1, 20 );
2、看代码,然后指出在各种调用中返回值为何种类型(难度系数85%):
public class MyClass<K, V>
{
public V this[K key]
{
get
{
throw new NotImplementedException();
}
}
}
public class MyClass
{
public static T[] MyMethod1<T>( T arg )
{
throw new NotImplementedException();
}
public static K MyMethod2<K, V>( V value, MyClass<K, V> dictionary )
{
throw new NotImplementedException();
}
}
MyClass<int, string> instance = new MyClass< int, string >();
??? result = MyClass.MyMethod1( MyClass.MyMethod2( instance[0], instance ) );//请指出返回类型
3、看代码,然后指出在各种调用中返回值为何种类型(难度系数90%):
public class MyClass<K, V>
{
public V this[K key]
{
get
{
throw new NotImplementedException();
}
}
}
public class MyClass
{
public static MyClass<V, K> MethodA<K, V>( MyClass<K, V> dictionary )
{
throw new NotImplementedException();
}
public static MyClass<MyClass<T, V>, K> MethodB<K, V, T>( MyClass<K, V> dictionary, T[] arg )
{
throw new NotImplementedException();
}
public static MyClass<K, V[]> MethodC<K, V>( MyClass<K, V> dictionary )
{
throw new NotImplementedException();
}
}
??? ōbj = MyClass.MethodA( MyClass.MethodB( instance, MyClass.MethodC( instance )[0] ) )[0]; //请指出返回类型。
四、.NET Framework和C#高级知识(.NET Framework和C#进阶)
1、看代码,然后回答问题(难度系数65%):
enum Fruit { Apple, Pear, Orange };
请问,Fruit.Apple.GetType().ToString()将得到什么结果?而typeof( Fruit ).GetType().ToString()呢?
2、先看代码,并指出下列程序是否存在编译时错误,存在什么错误(难度系数70%)?
public static void SomeMethod( long arg )
{
//...
}
//...
int i = 0;
int j = SomeMethod( i );//忽略类、方法体和命名空间