zoukankan      html  css  js  c++  java
  • C#的数据类型,strut和枚举的使用方法

    using System;

    namespace Holle_World
    {
      class Program
      {
      //enum枚举
      enum Week{ Monday, Tuesday, Wenesday, Thursday, Friday, Saturday, Sunday };

      // struct ,可自定义类型
      struct Person
      {  
        public string name;
        private bool sex;
        internal int age;
        //protected string x;

      }
      static void Main(string[] args)
      {  
        ///多少种变量类型,各有什么特点
        /// 常用的分为整型、浮点型、bool型、char型、引用型、decimal型
        //整型
        sbyte a = 0;//sbyte=System.Sbyte 8位有符号整数
        short b = 0;//short=System.Int16 16位有符号整数
        int c = 0; //int=System.Int32 32位有符号整数
        long d = 0;//long=System.Int64 64位有符号整数
        byte e = 0;//byte=System.Byte 8位无符号整数
        ushort f = 0;//ushort=System.UInt16 16位无符号整数
        uint g = 0;//uint=System.UInt32 32位无符号整数
        ulong h = 0;//ulong=System.UInt64 64位无符号整数

        //浮点型
        float I = 1.1f; //单精度
        double J = 1.1;//双进度,若无“f”,默认为双精度

        //bool(布尔)型
        bool k= true; //bool=System.Boolean true or false

        //char(字符)型
        char l = 'a';//cahr=System.Char 16位的字符

        //应用类型
        object m;
        string n = "abc";

        //类型的强制装换
        int o= Convert.ToInt16(k);//把布尔型转换成整型
      
        ///如何调用struct
        /// struct必须在main方法之外编写
        ///1、实例化对象
        ///2、实例化后的对象调用struct中所定义的变量并进行赋值
        Person person = new Person();
        person.name = "李";
        Console.WriteLine(person.name);

        /// enum 枚举的调用
        /// enum是给变量数个限定的选项,限定了变量的可能性
        /// var可以代替数据的类型,在.net3.5以上使用
        /// enum需要在main方法之外赋值申明
        var day = Week.Tuesday;
        Console.WriteLine(day);
        Console.WriteLine((int)Week.Wenesday);
        Console.ReadLine();
        }
      }
    }

  • 相关阅读:
    Hadoop 实现 TFIDF 计算
    关于Elasticsearch 使用 MatchPhrase搜索的一些坑
    SpringBoot jar包中资源加载问题
    gradle 将依赖打入Jar包的方法
    ES 在聚合结果中进行过滤
    Java c# 跨语言Json反序列化首字母大小写问题
    hadoop is running beyond virtual memory limits问题解决
    hadoop环境运行程序出现 Retrying connect to server 问题
    CSS的初步认识,基本选择器(CSS day1)
    day19 time模块
  • 原文地址:https://www.cnblogs.com/Small-Transparent/p/5109952.html
Copyright © 2011-2022 走看看