首页 > ASP.NET > The NOTE of learning ASP.NET [13] 关于.NET中的Constants,Enumerations,Structs

The NOTE of learning ASP.NET [13] 关于.NET中的Constants,Enumerations,Structs

Constants 即常量,可以像普通变量一样使用const来定义,但是它的值在应用程序运行中是不可以改变的,例如我们常见的圆周率。
Enumerations 是枚举型, 是一些相关的常量的集合,使用enum标识来定义。它有两个域,名字和数字域。使用时通过枚举量名.名字域来调用。
       例:enum weekDay
            {
        Sunday = 1,
        Monday = 2,
        Tuesday = 3,
        Wednesday = 4,
        Thursday = 5,
        Friday = 6,
        Saturday = 7,
            }
           我们调用的时候就可以使用weekDay.Sunday 这样来调用,返回值为1
 
Structs 及结构型, 和枚举型类似,但是相当于枚举类型的数字域可以存储任何类型数据。使用struct来定义
    例:struct Person
        {
            public string FirstName;
            public string LastName;
            public int Age;
              }
             Person person ;
        person.FirstName = "Lei";
        person.LastName = "Rong"
        person.Age = 25;
        System.Console.Write("{0} {1} is a {2} years old boy.",person.FirstName,person.LastName,person.Age);
 
 
Advertisements
分类:ASP.NET
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: