ZKX's LAB

值类型和引用类型的区别? 枚举是不是引用类型

2020-08-11知识15

程序枚举类型怎么引用,有实例吗? using System;定义枚举public enum Gendar{未知=0,男=1,女=2}在Student类中使用枚举public class Student{public Student(string name,Gendar sex){Name=name;Sex=sex;}public string Name{get;set;}public Gendar Sex{get;set;}}测试static class Program{static void Main(){Student s1=new Student(\"李红\",Gendar.女);Console.WriteLine(\"姓名:{0} 性别{1}\",s1.Name,s1.Sex);Student s2=new Student(\"张强\",Gendar.男);Console.WriteLine(\"姓名:{0} 性别{1}\",s2.Name,s2.Sex);Student s3=new Student(\"王平\",Gendar.未知);Console.WriteLine(\"姓名:{0} 性别{1}\",s3.Name,s3.Sex);}}C#中引用类型和值类型分别有哪些 C#的值类型包括:结构体(数值类型,bool型,用户定义的结构体),枚举,可空类型。br>;C#的引用类型包括:数组,用户定义的类、接口、委托,object,字符串。。java enum是一个引用还是一个值类型 在C#中算是值类型,但在Java中算引用。

#引用类型#c#

随机阅读

qrcode
访问手机版