• 您的位置:首頁 > 新聞動態(tài) > Unity3D

    unity3d C# 調(diào)用C程序封裝結(jié)構(gòu)體函數(shù)

    2023/10/30??????點擊:

    C#程序定義結(jié)構(gòu)圖的方式如下:

    public struct student  //結(jié)構(gòu)體名
    {
            //沒有public 修飾的成員變量 不能被訪問
    	 public string Name;
             public string Sex;
    	 public int Age;
             public  student(string name, string sex, int age)
             {
                   this.Name = name;
                   this.Sex = sex;
                   this.Age = age;
              }          
    }

    如果結(jié)構(gòu)體內(nèi)定義了靜態(tài)成員或者函數(shù), 則調(diào)用時只會被初始化次, 如:

    static student()
    {
                 Console.WriteLine("我是靜態(tài)函數(shù)");
    } 
    結(jié)構(gòu)體實例化方法:
    student boy1 = new Student("小明","男", 18); 
    student boy2 = boy1;