,1基本輸入輸出static void main(string[] args){ console.writeline("輸入焦點啥吧");string s=console.readline();console.writeline("歡迎光臨"+s);console.readline();}
2,結構類型的使用namespace{ struct student { public string stu_id; public string name; public int age; public int score; } class program { static void maini(string[] args) { student s; s.stu_id='' 09306101''; s.name=''小紅''; s.age=29; s.score=99; console.writeline(''學號:''+s.stu_id); console.readline(); } } }
3,數組的使用,求數組最大最小值static void mian(string[] args){ int max,min; int[] a=new int[10]{1,24,3,72,37,45,41,5,44,8};max=a[0];min=a[0];for(int i=1;i<a.length;i++){ if(max<a[i])max=a[i];if(min>a[i])min=a[i];}comsole.writeline(''最大值{0}'',max);comsole.writeline(''最小值{0}'',miin);console.readline(); } }}
4,string常用方法static void main(string[] args){console.writeline("請輸入使用者名稱:");string s=console.readline();if(string.compare(s,''wxy'')==0){console.writeline('' 開始示範方法了:");string str='' hello'';console.writeline("複製字串:{0},string.copy(str1));console.writeline("字串:{}",str.substring(3.2));console.writeline("插入:{0}'',str1.insert(3,"******"));}else{console.writeline("使用者名稱錯誤,退出程式");}console.readline();}}}
5,顯式轉換和隱式轉換static void main(string[] args){ console.writeline("隱式轉換:"); short i=1234; console.writeline(i); int s=i;console.writeline(s);console.writeline("顯式轉換:");long l=12345;console.writeline(l);int l1=(int)l;console.writeline(l1);console.readline();}
6,裝箱和拆箱static void main(string[] args){int i=123;object obj=123;int j=(int)obj;console.writeline("x={0}",i);console.writeline("obj={0}",obj);console.writeline("j={0}",j);console.readline();}
7,邏輯運算子執行個體
static void main(string[ ] args)
{
bool z;
int x=3,y=5;
z=x<y&&(--y<5);
console.writeline("y={0}",y);
console.writeline("z={0}",z);
z=x>y&&(x++>4);
console.writwline("x={0 }",x);
console.writeline("z={0 }",z);
console.readline();
}
8,條件運算子,求絕對值
static void main(string[ ] args)
{
console.writeline("請輸入一個數;");
int x;
x=int.parse(console.readline());
int y=x>=0?x:-x;
console.writeline("絕對值是{0}",y);
console.readline();
}