国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

【C#學(xué)習筆記】一、基礎(chǔ)知識

2019-11-17 02:18:08
字體:
供稿:網(wǎng)友

【C#學(xué)習筆記】一、基礎(chǔ)知識

1.1數(shù)據(jù)類型(P43)

類型

別名

允許的值

sbyte

System.SByte

-128~127

byte

System.Byte

0~255

short

System.Int16

-32768~32767

ushort

System.Uint16

0~65535

int

System.Int32

-2147483648~2147483647

uint

System.UInt32

0~4294967295

long

System.Int64

-9223372036854775808~9223372036854775807

ulong

System.UInt64

0~18446744073709551615

char

System.Char

一個Unicode字符,0~65535

bool

System.Boolean

true/false

sring

System.String

一組字符

float

System.Single

1.5*10^-45~3.4*10^38

double

System.Double

5.0*10^-324~1.7*10^308

decimal

System.Decimal

1.0*10^-28~7.9*10^28

1.2枚舉類型(P97)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//【例子1】枚舉的基本應(yīng)用

//1)賦值是可以使用其枚舉值賦值,如ct=emCardType.Temic;也可以直接用數(shù)值賦值,如ct = (emCardType)3;也可用將字符串經(jīng)過轉(zhuǎn)換// 賦值給枚舉變量,如ct = (emCardType)Enum.Parse(typeof(emCardType), "M1")

//2)使用WritenLine時其實是調(diào)用其ToString()方法將其轉(zhuǎn)換為字符串

//3)可以將沒有枚舉到的數(shù)值賦給枚舉變量,但ToString()方法顯示的字符串為其值

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

enum emCardType:byte

{

Temic,

Em=2,

ID,

M1

}

emCardType ct;

ct=emCardType.Temic ;

Console.WriteLine("ct is {0},value is {1}", ct,(byte)ct); //顯示"ct is Temic,value is 0"

ct++;

Console.WriteLine("ct is {0},value is {1}", ct,(byte)ct); //顯示"ct is 1,value is 1"

ct = (emCardType)Enum.Parse(typeof(emCardType), "M1");

Console.WriteLine("ct is {0},value is {1}", ct, (byte)ct); //顯示"ct is M1,value is 4"

ct = (emCardType)3;

Console.WriteLine("ct is {0},value is {1}", ct.ToString(), (byte)ct); //顯示"ct is ID,value is 3"

Console.ReadKey();

1.3數(shù)組

1)一維數(shù)組定義

int[] myIntArray = { 5, 9, 10, 2, 99 };

int[] myIntArray = new int[5];

int[] myIntArray = new int[5] { 5, 9, 10, 2, 99 };

2)多維數(shù)組定義

double[,] hillHeight = new double[3, 4];

double[,] hillHeight = { { 1, 2, 3, 4 }, { 2, 3, 4, 5 }, { 3, 4, 5, 6 } };

3)數(shù)組的數(shù)組

int [][] myarray

myarray=new int[2][];

myarray[0]=new int[3];

myarray[1]=new int[4];

myarray=new int[3][](new int[]{1,2,3},new int[]{1},new int[]{1,2});

foreach (int[] subarray in myarray)

{

foreach(int nValue in subarray)

Console.WriteLine(nValue);

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//【例子1】數(shù)組復(fù)制

//若直接使用=號則兩個數(shù)組引用相同的值,要使用CopyTo方法進行復(fù)制

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int[] myInt = new int[5]{5,2,1,8,4};

foreach (int i in myInt)

Console.Write(i + ",");

Console.WriteLine("");

int[] myInt2=new int[5];

myInt.CopyTo(myInt2,0);

//myInt2 = myInt;

myInt[1] = 3;

foreach (int i in myInt2)

Console.Write(i + ",");

1.4委托(P137)

【例子1

class PRogram

{

delegate double ProcessDelegate(double param1,double param2);

static double Multiply(double param1,double param2)

{

return param1*param2;

}

static double Divide(double param1,double param2)

{

return param1/param2;

}

static void Main(string[] args)

{

ProcessDelegate process;

if (input=="M") //根據(jù)輸入的不同將其實例化為不同的函數(shù)

process=new processDelegate(Multiply);

else

process=new processDelegate(Divide);

double fRet=process(f1,f2);

}

}

【例子2

private delegate int mif_selecom(int nCom, int nBaud);

private void button1_Click(object sender, EventArgs e)

{

IntPtr pDll = LoadLibrary("LC32RFRW.dll");

IntPtr pAddressOfFunctionToCall = GetProcAddress(pDll, "mif_selecom");

mif_selecom DoSeleCom = (mif_selecom)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall,

typeof(mif_selecom));

}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 琼海市| 资兴市| 宽城| 泾源县| 新余市| 锡林郭勒盟| 留坝县| 根河市| 景泰县| 涡阳县| 天长市| 龙口市| 景东| 彭泽县| 明光市| 海安县| 隆安县| 沙坪坝区| 阳高县| 翁牛特旗| 城固县| 贵南县| 岐山县| 阳东县| 巴彦县| 台中市| 安顺市| 尚义县| 北辰区| 沈丘县| 驻马店市| 探索| 磴口县| 朝阳市| 安化县| 永定县| 宜兴市| 开封县| 卓资县| 罗田县| 湖州市|