zoukankan      html  css  js  c++  java
  • 结构

    结构类型:

    一次性声明多个不同类型的变量

    结构的语法和用法:

    [访问修饰符]  struct  结构名

    {

    字段1;

    字段2;

    字段3

    }

    定义好一个结构后,就可以直接声明相应的变量了。声明好变量后,通过变量名.成员名来访问结构的成员

     1 namespace _02结构
     2 {
     3     public enum Gender
     4     { 
     5         男,
     6  7     }
     8     public struct Person
     9     {
    10         public string name;
    11         public int age;
    12         public Gender sex;
    13     }
    14     class Program
    15     {
    16         static void Main(string[] args)
    17         {
    18             Person onePerson;
    19             onePerson.name = "张三";
    20             onePerson.age = 22;
    21             onePerson.sex = Gender.男;
    22             Console.WriteLine("我叫{0},今年{1}岁,性别:{2}",onePerson.name,onePerson.age,onePerson.sex);
    23 
    24             Person lsPerson;
    25             lsPerson.name = "李四";
    26             lsPerson.age = 20;
    27             lsPerson.sex = Gender.女;
    28             Console.WriteLine("我叫{0},今年{1}岁,性别:{2}",lsPerson.name,lsPerson.age,lsPerson.sex);
    29 
    30             Console.ReadKey();
    31 
    32         }
    33     }
    34 }
    View Code
  • 相关阅读:
    perimeter of squares
    map
    django路由
    for的骚用法
    3和5的倍数相加和
    PeteCake 字典和最小值
    Find the missing letter
    实现简单的ssh功能
    开源运维工具体系
    vsftp在iptables中的配置
  • 原文地址:https://www.cnblogs.com/kongbei2013/p/3254953.html
Copyright © 2011-2022 走看看