.NET笔试题集(一):https://www.cnblogs.com/Jacob-Wu/p/5667502.html
C#常见面试题(附答案)
【学习笔记】C#面试题(一)
C# .NET面试题(100道面试题)
------------------------------------------------------------------------------------------------------------
输出结果:
public struct Point
{
public int x;
public int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
}
Point p1 = new Point(100, 100);
Point p2 = p1;
p1.x = 200;
Console.WriteLine("{0},{1}", p1.x, p2.x);
答案:
200,100
解答:结构体是复制传递的。
public Point
{
public int x;
public int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
}
Point p1 = new Point(100, 100);
Point p2 = p1;
p1.x = 200;
Console.WriteLine("{0},{1}", p1.x, p2.x);
答案:
200,200
解答:Point类地址指向X内容都是200
------------------------------------------------------------------------------------------------------------
class Program
{
static void Main(string[] args)
{
MyClass y = new MyClass();
BaseClass x = y;
x.i = 100;
Console.WriteLine("{0},{1}", x.i, y.i);//100,0 x.i = 100,已经给他赋值了100,所以x.i输出100.而y.i,y是myclass的一个对象,定义之后没做任何赋值的动作,而int的默认值...
Console.ReadLine();
}
}
class BaseClass
{
public int i;
}
class MyClass:BaseClass
{
public new int i;
}
------------------------------------------------------------------------------------------------------------
以下程序的输出结果是(b)。
enum Color
{ Red, Green = 2, Blue }
static void Main(string[] args)
{
Color c = 0;//所有能确定为0的常量表达式都能隐式的转换成Enum,所以Color c = 0;并不会报错。如果Color c = 1会报错
Color c1 = (Color )2;
Console.WriteLine("{0},{1}", c,c1 );
Console .Read ();
}
a) Green,Red b) Red,Green c) Red,Blue d) Green,Blue
------------------------------------------------------------------------------------------------------------