int int_value = 101;
//调用*int_value*的比较方法与整型*2*进行进行比较 int_value.CompareTo(2); //在控制台输出 Console.WriteLine(int_value.ToString());
sbyte(System.SByte)安全
short(System.Int16)ide
int(System.Int32)函数
long(System.Int64)ui
byte(System.Byte)this
ushort(System.UInt16)code
uint(System.UInt32)orm
ulong(System.UInt64)对象
char(System.Char)继承
float (System.Single)
double(System.Double)
int[] int_array = new int[10];
在堆内存中一次初始化10个int类型的存储空间
自动初始化这10个元素
将10个元素存储到刚刚分配的内存空间内
object[] obj_array = new object[10];
在堆内存中分配一次空间
不会自动初始化任何元素
obj_array[i]
都是null当有代码初始化某个元素时,对应元素的存储空间会分配在堆内存上
obj_arr[i]=new object();
object item = new objct();
new
关键字在堆内存中分配内存空间,而且返回该内存空间的地址
item
存储分配后返回的内存地址
struct
定义public struct LORect { private float x; private float y; private float width; private float height; }
public LORect(float x,float y,float width,float height) { this.x = x; this.y = y; this.width = width; this.height = height; }
public float X{ set{ this.x = value; } get{ return this.x; } }
LORect frame = new LORect(0f,0f,100f,100f);
enum
定义public enum LOControlType { LOControlTypeNormal = 0, LOControlTypeHighlight = 1, LOControlTypeDisable = 2, }
LOControlType type = LOControlType.LOControlTypeNormal;
public class LOPerson { private string name; private int age; }
public LOPerson(){}
public LOPerson(string name){this.name = name;}
public LOPerson(string age){this.age = age;}
多个参数的构造函数
public LOPerson(string name,int age) { this.name = name; this.age = age; }
public void SayHi() { Console.WriteLine (this.name + “: Hello”); }
~LOPerson() { this.name = null; this.age = 0; }
在析构函数中,将引用类型成员变量置为null,内存处理
在析构函数中,将值类型成员变量置为默认值,程序逻辑安全
public class LOStudent:LOPerson { private float score; }
public LOStudent(float score):base() { this.score = score; }
public LOStudent(int age):base(age){}
在构造函数的继承中,都会先调用父类的构造函数
public void SayHello() { base.SayHi(); Console.WriteLine (“this.SayHi”); }
~LOStudent() { this.score = 0f; }
子类和父类的析构函数的执行顺序
1.自动调用子类的析构函数
2.自动调用父类的析构函数
不须要特别语法指名
Attribute
定义[AttributeUsage(AttributeTargets.Property)] public class LOTypeAttribute:Attribute { public string Type{set;get;} }
public class LOPeople { [LOType(Type=“NoHealthy”)] public string hobby{set;get;} }
PropertyInfo item = property_list[0]; LOTypeAttribute attribute = (LOTypeAttribute)Attribute.GetCustomAttribute(item,typeof(LOTypeAttribute)); Console.WriteLine (attribute.Type);
using System.Reflection;
Type
LOPeople people = new LOPeople(); people.hobby = “Smoke”; Type p_type = people.GetType();
获取属性列表
PropertyInfo[] property_list = p_type.GetProperties();
获取指定属性
PropertyInfo property = p_type.GetProperty(“hobby”);
方法
获取people对象的属性值 .GetValue()
property.GetValue(people,null);
设置people对象的属性值 .SetValue()
property.SetValue(people,”Drink”,null);
获取方法列表
MethodInfo[] method_list = p_type.GetMethods();
获取指定方法
MethodInfo method = p_type.GetMethod(“SayHi”);
方法调用
Invoke()
方法的参数列表
method.GetParameters();
方法的返回值
method.ReturnType;
获取成员列表
MemberInfo member_list = p_type.GetMembers();
获取指定成员
MemberInfo[] member= p_type.GetMember(“name”);
获取构造函数列表
ConstructorInfo[] constructor_list = p_type.GetConstructors();
获取指定构造函数
ConstructorInfo constructor = p_type.GetConstructor(new Type[]{typeof(int)});
delegate
public delegate void LODataSource(List<int> data_list);
LODataSource dataSource;
dataSource = (List<int> data_list)=>{ foreach (int item in data_list) { Console.WriteLine (item.ToString()); } } ;
void ProcessData(List<int> data_list) { foreach (int item in data_list) { Console.WriteLine (item.ToString()); } }
dataSource = new LODataSource(ProcessData);
dataSource = ProcessData;
interface
public interface LOInterface{ void SayNice(); }
public class LOTeacher:LOInterface{ private string name; public void SayNice() { Console.WriteLine (this.name + “: Nice”); } }
public class LOManager:LOInterface{ private string name; public void SayNice() { Console.WriteLine (this.name + “: Nice”); } }