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 = "";

  • 相关阅读:
    volatile 关键字介绍
    hystrix 线程数,超时时间设置测试
    idea git tag 管理
    wget 认知及常用命令【转载】
    yum 认知及使用
    zuul 性能分析
    java 内存分析
    eureka-8-Eureka 的健康检查
    eureka-7-多网卡下的ip选择
    鼠标拖动div宽/高值增加与减小
  • 原文地址:https://www.cnblogs.com/franky2015/p/4646268.html
Copyright © 2011-2022 走看看