zoukankan      html  css  js  c++  java
  • 结构体

    结构体:就是一个自定义的集合,里面可以放各种类型的元素,用法大体跟集合一样。

    一、定义的方法:注:结构体一般定义在Main函数的上面,Class下面,作为一个类,参数前面加上public代表公用变量,(也可用protect-受保护的,private-私有的,这2个基本不用)

    struct student//student是结构体的名字

    {

    public int +变量名;

    public string +变量名;

    public int  +变量名;

    }

    二、用法:

      在main主函数外面定义了一个名称为student的结构体,以便于main函数之中使用。

     student st = new student();//这句话是在main函数之中定义了一个名为st的student类型的结构体。

          下面开始为里面的每个元素赋值:(结构体名+点+结构体里面的变量名称=值)

    class Program
        {
            struct student
            {
    
                public int nianling;
    
                public int fenshu;
    
                public string name;
    
                public string sex;
    
                public int sum;
    
            }
    
    
    
            static void Main(string[] args)
            {
                student st = new student();
    
                    st.nianling = 22;
    
                    st.fenshu = 80;
    
                    st.name = "小李";
    
                
    
            }
        }

    三、结构体的使用:

    1.使用结构体来定义变量
    Student s1 = new Student();
    2.给结构体变量赋值。
    s1.Name = "";
    s1.NO = "";

  • 相关阅读:
    C#使用各种时间戳及转换
    Rust借用机制的理解分析
    C# QRCoder 生成二维码
    Android 使用 JCIFS 访问共享文件
    Linux samba 创建共享盘
    WPF 等待对话框
    IIS实现Nginx功能:转发
    js jquery ajax跨域
    依赖注入
    .net standard
  • 原文地址:https://www.cnblogs.com/franky2015/p/4646268.html
Copyright © 2011-2022 走看看