• 您的位置:首页 > 新闻动态 > Unity3D

    unity3d C# 调用C程序封装结构体函数

    2023/10/30      点击:

    C#程序定义结构图的方式如下:

    public struct student  //结构体名
    {
            //没有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;
              }          
    }

    如果结构体内定义了静态成员或者函数, 则调用时只会被初始化一次, 如:

    static student()
    {
                 Console.WriteLine("我是静态函数");
    } 
    结构体实例化方法:
    student boy1 = new Student("小明","男", 18); 
    student boy2 = boy1;