日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#結(jié)構(gòu)體定義的詳解

C#結(jié)構(gòu)體定義的情況:

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:國際域名空間、雅安服務(wù)器托管、營銷軟件、網(wǎng)站建設(shè)、南崗網(wǎng)站維護(hù)、網(wǎng)站推廣。

C#結(jié)構(gòu)體定義也可以象類一樣可以單獨(dú)定義.

 
 
 
  1. class  a{};
  2. struct a{};

C#結(jié)構(gòu)體定義也可以在名字前面加入控制訪問符.

 
 
 
  1. public struct student{};
  2. internal struct student{};

如果結(jié)構(gòu)體student沒有publice或者internal的聲明 類program就無法使用student結(jié)構(gòu)定義 obj對象

如果結(jié)構(gòu)體student的元素沒有public的聲明,對象obj就無法調(diào)用元素x

因?yàn)槟J(rèn)的結(jié)構(gòu)體名和元素名是private類型

C#結(jié)構(gòu)體定義之程序:

 
 
 
  1. using System;
  2. public struct student
  3. {
  4.    public int x;
  5. };
  6. class program
  7. {
  8. public static void Main()
  9. {
  10.  student obj=new student();
  11.  obj.x=100;   
  12. }
  13. };

在結(jié)構(gòu)體中也可以定義靜態(tài)成員與類中一樣,使用時(shí)必須用類名,或結(jié)構(gòu)名來調(diào)用不屬于實(shí)例,聲明時(shí)直接定義.

C#結(jié)構(gòu)體定義程序:

 
 
 
  1. using System;
  2. public struct student
  3. {
  4.  public static int a = 10;
  5. };
  6. class exe
  7. {
  8.  public static void Main()
  9. {
  10.  Console.WriteLine( student.a = 100);
  11. }
  12. };

 
 
 
  1. using System;
  2. class base
  3. {
  4. public struct student
  5. {
  6.  public static int a = 10;
  7. };
  8. }
  9. class exe
  10. {
  11.  public static void Main()
  12. {
  13.  Console.WriteLine( base.student.a = 100);
  14. }
  15. };

在結(jié)構(gòu)體中可以定義構(gòu)造函數(shù)以初始化成員,但不可以重寫默認(rèn)無參構(gòu)造函數(shù)和默認(rèn)無參析構(gòu)函數(shù)

C#結(jié)構(gòu)體定義程序:

 
 
 
  1. public struct student
  2. {
  3.    public int x;
  4.    public int y;
  5.    public static int z;
  6.    public student(int a,int b,int c)
  7. {
  8. x=a;
  9. y=b;
  10.  student.z=c;
  11. }
  12. };

在結(jié)構(gòu)體中可以定義成員函數(shù)。

C#結(jié)構(gòu)體定義程序:

 
 
 
  1. public struct student
  2. {
  3.    public void list()
  4. {
  5. Console.WriteLine("這是構(gòu)造的函數(shù)");
  6. }
  7.  };

結(jié)構(gòu)體的對象使用new運(yùn)算符創(chuàng)建(obj)也可以直接創(chuàng)建單個(gè)元素賦值(obj2)這是與類不同的因?yàn)轭愔荒苁褂胣ew創(chuàng)建對象

C#結(jié)構(gòu)體定義程序:

 
 
 
  1. public struct student
  2. {
  3.    public int x;
  4.    public int y;
  5.    public static int z;
  6.    public student(int a,int b,int c)
  7. {
  8. x=a;
  9. y=b;
  10.  student.z=c;
  11. }
  12. };
  13. class program
  14. {
  15.  public static void Main()
  16. {
  17.   student obj=new student(100,200,300);
  18.   student obj2;
  19.   obj2.x=100;
  20.   obj2.y=200;
  21.   student.z=300;
  22. }
  23. }

在使用類對象和函數(shù)使用時(shí),使用的是引用傳遞,所以字段改變

在使用結(jié)構(gòu)對象和函數(shù)使用時(shí),是用的是值傳遞,所以字段沒有改變

C#結(jié)構(gòu)體定義程序:

 
 
 
  1. using System;
  2. class class_wsy
  3. {
  4. public int x;
  5. }
  6. struct struct_wsy
  7. {
  8. public int x;
  9. }
  10. class program
  11. {
  12. public static void class_t(class_wsy obj)
  13. {
  14. obj.x = 90;
  15. }
  16. public static void struct_t(struct_wsy obj)
  17. {
  18. obj.x = 90;
  19. }
  20. public static void Main()
  21. {
  22. class_wsy obj_1 = new class_wsy();
  23. struct_wsy obj_2 = new struct_wsy();
  24. obj_1.x = 100;
  25. obj_2.x = 100;
  26. class_t(obj_1);
  27. struct_t(obj_2);
  28. Console.WriteLine("class_wsy obj_1.x={0}",obj_1.x);
  29. Console.WriteLine("struct_wsy obj_2.x={0}",obj_2.x);
  30. Console.Read();
  31. }
  32. }

C#結(jié)構(gòu)體定義程序運(yùn)行結(jié)果為:

 
 
 
  1. class_wsy obj_1.x=90
  2. struct_wsy obj_2.x=100

C#結(jié)構(gòu)體定義的基本內(nèi)容就向你介紹到這里,希望對你了解C#結(jié)構(gòu)體定義有所幫助。


新聞標(biāo)題:C#結(jié)構(gòu)體定義的詳解
網(wǎng)站鏈接:http://www.5511xx.com/article/dpigedg.html