1.結構體裡面是否可以有屬性?
可以有屬性。實測代碼以及截圖。
In C#, we can use the following statement to convert a string s to an integer num 124
A.int num = Convert.ToInt32(s);
B.int nym = Int32.Parse(s);
C.int num = s.ToInt();(不可以)
D.int num = int.Parse(s);(測試可以過)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fraction
{
public struct StructTest
{
private int x;
public int X
{
get { return x; }
set { x = value; }
}
public StructTest(int _x)
{
x = _x;
}
}
class Program
{
static void Main(string[] args)
{
StructTest str = new StructTest();
str.X = 1;
Console.WriteLine(str.X);
string s = "123";
int num1 = Convert.ToInt32(s);
int num2 = Int32.Parse(s);
//int num3 = s.ToInt();
int num4 = int.Parse(s);
Console.WriteLine("num1="+num1);
Console.WriteLine("num2="+num2);
//Console.WriteLine(num3);
Console.WriteLine("num4="+num4);
Console.Read();
}
}
}

Property 可聲明在 class, struct, interface裡!
使用屬性的好處:
允許只讀或者只寫字段;
可以在訪問時驗證字段;
接口和實現的數據可以不同;
替換接口中的數據。

2.參數傳遞的方式:按值傳遞、按引用傳遞。沒有按位置傳遞、沒有按名稱傳遞。
3.LINQ查詢:LINQ to Object, LINQ to XML, LINQ to ADO.NET 包括兩種獨立的技術: LINQ to DataSet 和 LINQ to SQL
對於LINQ to Object可以查詢數組等裡面的數據;
對於LINQ to SQL可以查詢SQL能夠查詢的表中的數據;
對於LINQ to XML可以查詢XML文檔的標簽等;
對於LINQ to DataSet可以查詢DataSet中的數據;
3.委托的形式
f = delegate(int x){return x + 1;};
f = x => x+1;

測試代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lambda
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
Func<int, int> f1 = x => 2 * x + 1;
Func<int, int, bool> f2 = (x, y) => x > y;
Func<string, int, string> f3 = (x, y) => x.Substring(y);
Func<int, int> f4 = (x) => sum += x;
Action a1 = () => { System.Console.WriteLine("HelloWorld"); };
Action <int> a2 = (x) => { System.Console.WriteLine(x); };
Action <bool> a3 = (x) => { System.Console.WriteLine(x); };
Action<string> a4 = (x) => { System.Console.WriteLine(x); };
for (int i = 1; i <= 10; i++ )
{
f4(i);
}
a2(sum);
a1();
a2(f1(1));
a3(f2(3, 5));
a4(f3("Zhengpengfei", 5));
System.Console.Read();
}
}
}

4.內嵌類型可以是類、結構、結構體、枚舉、委托
具體見PPT
5.類與結構體、類與接口、重載(overloading)與重寫(overriding)、虛方法與抽象方法、托管代碼與非托管代碼





6.Constants can be declared static (True)
在C#中const與static不能同時修飾變量;


7.裝箱boxing:值類型轉換為引用類型;
拆箱unboxing:引用類型轉為值類型。

8.An interface member is implemented or _inherited__from a base class
接口的成員要麼自己定義要麼繼承自父類。
接口不能包含常量、字段、操作符、構造函數、析構函數、任何靜態成員、方法的實現;
9.What is the difference between private assembly and public assembly?
private assembly只能被一個應用程序使用、保存在應用程序目錄中、不要求強命名、無法簽名;
public assembly可以被所用應用程序使用、保存在全局程序集中、必須有一個強命名、可以簽名
另外強命名包括四個部分:Assembly的命名、Assembly的版本號、Assembly的文化屬性、Assembly的公鑰。
10.Which of the following are correct ways to pass a parameter to a attribute?
1) By value 2)by reference 3)by position 4)by name
A 1 ,2 B 3,4 C 1,2,3,4 D1,2,3
