C#基础学习笔记

1.decimal小数类型  16字节   如1.23123m

2.c#使用unicode

3.c#的object是System.Object的别名,可以给他任意的类型

类型安全:赋初值

数据隐式转换:浮点类型不可转小数类型、数值类型不可转字符类型    

float只有7位精度、Math.Round进行四舍五入

装包(int——>object)拆包(object——>int):栈堆

4. 引用类型的比较:object.Equals()

表达式1 = 表达式2 as 类型    表达式1、2:对象类型和字符类型即引用类型

Type t = typeof(object);//GetType()

MethodInfo[] x = t.GetMethods();

checked或unchecked表达式、语句块:检查数据溢出

5.string.Format()

double f = 1234.56;

f.Format("C",null);


string huobi = "$3.56";

double.Parse(huobi,NumberStyles.Any)


DateTime shijian = new DateTime(1949,10,1);

shijian.DayOfWeek;

shijian.Format("d",null);


Console.WriteLine("i=0x{0,8:X}\td={1,10:F3}",i,d);

6.Array  Array.CreateInstance(typeof(Int32),5)、setvalue、GetLowerBound              Sort、Reverse、Indexof

7.using COL = System.Console;

COL.WriteLine("hello");

8.sealed和abstract只能使用其中之一

readonly只读域   public readonly static int field;//域的三个关键字

索引:IndexClass t = new IndexClass();   t[1] = 244;

private int[] array = new int[10];

public int this[int index]

{

get{

if(index>=0 && index<10)

return array[index];

}

set{

if(index>=0&&index<10)

array[index] = value;

}

}

params关键字:void fun(params int[]  array){}形参的个数可以变化

internal:不被其他项目工程使用,如做成dll的时候

造型(cast):

Employee e = new Employee();

object o = e;

Manager m = new Manager();

e = (Employee)m;

9.delegate void MyDelegate(int i);

MyDelegate m1 = new MyDelegate(CBase.print);//静态或实例

MyDelegate m2 = new MyDelegate(CBase.write);

MyDelegate m3 = m1 + m2;

10.代理写到里面、外面、多重代理、事件(热水器、观察者)

11.结构是个封闭类(能继承接口)、不允许声明一个没有参数的构造体、只能为static赋初值、可以不用new

枚举与整数间转换要显式    System.Enum  ToObject、FromString转换为枚举,其他取属性

12.异常:内存、下标、除数为零、输入     System.Exception系统或自定义

finally不管有没有异常都会被执行,有异常时程序会退出

System.Exception的属性:HelpLink、InnerException、Message、Source、StackTrace、TargetSite

13.编译时输出:#error 字符串  不生成可执行文件 #warning   #line 行号["文件名"]

[Conditional("DEBUG")]    [Obsolete("error",true)]

14.不安全的代码:unsafe

fixed(int *p = array)//防止被系统回收

{

for(int i =0;i < array.Length;i++)

{

p[i]+=101;

}

}

sizeof(Weekdays) //4字节          不安全代码、不能对引用类型、不能操作变量数组

int *array = stackalloc int[10];//类似new,只不过是用在指针

15.[DllImport("User32.dll")]

public static extern int MessageBox(int h,string m,string c,int type);

自定义代码属性:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct,AllowMutiple = true)]

public class AuthorAttribute:Attribute

{}

使用:2种

[Author("Way",Version  = 1.1)]

Attribute[] attri = Attribute.GetCustomAttributes(typeof(MyClass));

MemberInfo.GetCustomAttributes();   Type(typeof)及MethodInfo都继承MemberInfo

16.一个类成员里面也可有该类的对象

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值