C 類和結構區別的總結 一

2021-09-04 15:15:26 字數 1654 閱讀 6834

using system;

using system.collections.generic;

using system.text;

",a,i);

int b = new int[10];

console.writeline(b[3]);

structone soinstanceone = new structone ();

console.writeline("soinstanceone::", soinstanceone.filed1, soinstanceone.filed2);

structone soarrayone = new structone[10];

console.writeline("soarrayone::",soarrayone[2].filed1,soarrayone[2].filed2 );

soarrayone[0].people = new string[4];

soarrayone[0].people[0] = "男";

soarrayone[0].people[1] = "18";

soarrayone[0].people[2] = "jack";

foreach (string peoplejack in soarrayone[0].people)

soinstanceone.people = new string[3];

soinstanceone.people[0] = "女";

soinstanceone.people[1] = "17";

soinstanceone.people[2] = "alice";

foreach (string peoplealice in soinstanceone.people)

console.writeline(structone.filed4);

soinstanceone.structonemethodone();

classone test = new classone();

console.writeline ("test:");

console.writeline ("::",test.cfiled1,test.cfiled2 ,test.cfiled3 ); //列印0::false

console .readline (); }

struct structone

;//結構中不能有例項字段初始值設定項,意思就是不能為例項字段賦值

//private int filed3 = 3;  //不能有例項字段初始值設定項,意思就是不能為例項字段賦值

public  static int filed4 = 4; //結構中可以為靜態字段賦值

private const string cona = "cona"; //結構中可以為常數字段賦值,因為常數屬於static

private static string strname = "john"; //結構中可以為靜態字段賦值

public static string anotherpeople = ; //結構中可以為靜態陣列賦值

public bool bresult;

public void structonemethodone()

} class classone

} }

C 類和結構區別的總結 一

using system using system.collections.generic using system.text a,i int b new int 10 console.writeline b 3 structone soinstanceone new structone conso...

C 類和結構區別的總結 一

using system using system.collections.generic using system.text a,i int b new int 10 console.writeline b 3 structone soinstanceone new structone conso...

C 中類和結構體區別的整理(筆記)

1.在結構體中可以宣告字段,但是宣告欄位的時候是不能給初始值的 其實類中的字段也不能給初始值,編譯器會自動把賦值操作放在建構函式裡 2.建構函式在類中如果不寫會自動新增乙個無參建構函式,構造體中的無參建構函式不能手寫 3.結構體的建構函式必須為每個欄位都賦值 4.構造體可以直接宣告變數 不用new ...