C 中基本知識

2021-08-22 07:37:42 字數 1496 閱讀 3456

當資料轉換到asp.net頁面時,大部分都是以文字的形式存在的。有時候為了輸出,單單使用顯示或者隱式轉換都是不行的,就需要本節說到的資料轉換。

字串輸出:

int intage=21;

string strage=intage.tostring();

轉換datetime值時,可以通過在括號內放置乙個可選的引數來指定時間的輸出樣式。eg:datecou.tostring(「d「);

格式化**及其含意:

d——以下列格式給出日月年:thursday,september 21,2001

g——09/22/2001 09:12:23

t——給出時分:01:23

d——mm/dd/yyyy

資料輸入

convert函式大全:

convert.toboolean();

convert.tobyte();

convert.tochar();

convert.todatetime();

convert.todecimal();

convert.todouble();

convert.toint16();

convert.toint32();

convert.toint64();

convert.tosbyte();

convert.tosingle();

convert.touint16();

convert.touint32();

convert.touint64();

七、常量

賦值:const intabsolutezero=-273;

必須在類定義中宣告,而不能超脫類來定義。

八、結構化的資料型別

1、陣列

宣告乙個陣列:string strsz;

為了生成乙個已宣告的陣列,必須進行初始化:strsz=new string[5];

宣告的同時進行初始化:string asp=new string[44];

陣列的下標從0開始。

變數的賦值:asp[0]=「sdf「;

asp[2]=「sdf「;

或者:string asp=new string;

string asp=new string[2];

string asp=;

看例項:

多維陣列:

string [,] strstr1=new string[3,2];

c#不限制陣列的大小,只有記憶體來限制它,然而在實際使用過程中,當有超過三維以上的陣列時,就需要考慮其它的解決方案,比如物件。

不規則陣列:

string strnre=new string[2];

string strnre[0]=new string[8];

string strnre[1]=new string[2];

2、結構

定義:struct nameabc;

3、列舉

enum gender;

C 中基本知識

當資料轉換到asp.net頁面時,大部分都是以文字的形式存在的。有時候為了輸出,單單使用顯示或者隱式轉換都是不行的,就需要本節說到的資料轉換。字串輸出 int intage 21 string strage intage.tostring 轉換datetime值時,可以通過在括號內放置乙個可選的引數...

C 基本知識

內聯函式 在c 98的標準下為63個關鍵字 1.普通的命名空間 namespace n1 n1為命名空間的名稱 2.命名空間可以巢狀 namespace n2 namespace n3 3.同乙個工程中允許存在多個相同名稱的命名空間,編譯器最後會合成同乙個命名空間中。1.加命名空間名稱及作用域限定符...

c 基本知識

1.類 包含某一物體的基本屬性的抽象。2.物件 具體指某乙個物體。實實在在存在的東西。3.建構函式 負責類建立物件的函式。如果類沒有宣告建構函式,c 編譯器會提供預設的無參的建構函式。這個函式只負責建立物件,不負責物件初始化工作。4.析構函式 負責釋放物件,記憶體的 5.變數訪問修飾符 public...