Title: Class 2
1??????
2???
34-1 ??
4???????????
54-2 Jagged Array
- C???????????????,???????????????,???Jagged
Array??????? - DataType arrayname new
DataTypesize - ????Jagged Array?????
- int myjag new int 3
- myjag1 new int2
- myjag2 new int4
- myjag0 new int3
myjag00 myjag01 myjag02
myjag10 myjag11
myjag20 myjag21 myjag22 myjag23
6????
- ?????????????Array???????,??????????????????????,?
?????? - ??????VS???????
- ??,???????????????????
74-3 ArrayList??
- ? .NET Framework??????ArrayList??,?????
????????,????????????Object,??????????????????????
? - ??ArrayList?System.Collections???????
84-3 ArrayList??
ArrayList????
????? ??
Count?? ??ArrayList???????????????
Length?? ????????
Add()?? ?custName?????ArrayList????
Insert()?? ??????ArrayList???????count?????,??????????
Remove()?? ?ArrayList???????????custName??????
Clear()?? ??ArrayList?????????
CopyTo()?? ?ArrayList??????????????????????
IndexOf()?? ??ArrayList???????????????????,???-1?
Sort()?? ?ArrayList????????????(???)?
Reverse()?? ?ArrayList??????????ArrayList??Sort??Reverse????ArrayList??????
BinarySerach()?? ???????ArrayList????????,??????????????????????????????,????ArrayList??????
94-4 ?????
- ??????????
string address string city "???", street
"?????" int no 168 address city street
no // ????????168 address"?" //
????address??????? char char1"MIB??"3
//???????0?????3??? char char2address5
//??address???0?????5???
???????Unicode??,??byte??address5???????
104-4 ?????
??char.Equals(objectA,objectB)
?????A???B?????true,????false ??bool result
char char1a char char2c
resultchar.Equals(char1,char2) // false
Console.WriteLine(result.ToString())
//??False
?????????????
114-4 ?????
- C .NET??????
??str1.Equals(str2) ????str1?????str2???? ??i
f(str1.Equals(str2)) .... ? if
(str1str2) .... ????
12???
135-1 ??
- ?????????,????????C .NET?????????????????????????
?????????????? - ?????????(???)???????,????C .NET?????????????????
?,???????????????,????????????????????? - ????????,???????,?????????????
145-1 ??(?)
- C .NET????????????????
- ???????
- ????????
- ??
155-2 ??????
access???????? static????????????????????,???????
?????
16????????
- ???,??????????Main????,??????Main?????CheckID,???M
ain????????,???Main???CheckID??????static? - ??????????????????,??????????????(??????????),???
?????????????
175-2 ??????(?)
??????????? ? ? ? ?
public ??????????????????
protected ????????????????????????????????
internal ?????????????????
protected internal ????????????????????????
private ?????????????(??)
185-2 ??????(?)
- ??????
- 1. ?C .NET??????????????????????
195-2 ??????(?)
205-2 ??????(?)
215-3 ???????
- ???? (Call by value)
- ?????A???????B?,??A?????????????B?
???????,??????????????????,??B???????????????,????
???A??????
225-3 ???????(?)
?????_???
- // Filename cs_CallValue.sln
- 1. using System
- 2. namespace cs_CallValue
- 3.
- 4. class Class1
- 5.
- 6. private static void CallValue(int x, int y)
- 7.
- 8. int z
- 9. x20
- 10. y30
- 11. Console.WriteLine ("\n??? ???
x 0 y1 ",x,y) - 12. zx //?????????x,y????
- 13. xy
- 14. yz
- 15. Console.WriteLine ("\n??? ???
x 0 y1 ",x,y) -
- 17. STAThread
- 18. static void Main(string args)
235-3 ???????(?)
?????_???
21. int a 10 22. int b 12
23. Console.WriteLine ("\n???? ??????
a 0 b1 ",a,b) 24. CallValue(a, b)
25. Console.WriteLine ("\n???? ???????? a
0 b1 ",a,b) 26. Console.ReadLine()
27. 28. 29.
????
245-3 ???????(?)
- ???? (Call by reference)
- ??A????B?,??????B??????????A,?????
????????????????????????????????????,?????????,???
????????,?????B??????????A,?????????????
255-3 ???????(?)
?????_???
// Filename cs_CallRef.sln 1. using System 2.
namespace cs_CallRef 3. 4. class
Class1 5. 6. private static void CallRef(ref
int x, ref int y) 7. 8. int z 9.
x20 10. y30 11. Console.WriteLine
("\n??? ??? x 0 y1
",x,y) 12. zx //?????????x,y???? 13.
xy 14. yz 15. Console.WriteLine
("\n??? ??? x 0 y1
",x,y) 16. 17. STAThread 18. static void
Main(string args) 19. 20.
Console.WriteLine("\n Call By Reference
???? \n")
265-3 ???????(?)
?????_???
21. int a 10 22. int b 12
23. Console.WriteLine ("\n???? ?????? a
0 b1 ",a,b) 24. CallRef(ref a, ref b)
25. Console.WriteLine ("\n???? ??????? a
0 b1 ",a,b) 26. Console.ReadLine()
27. 28. 29.
????
275-3 ???????(?)
- ???? (Output parameter)
- ?????????????????????????????????????
??????????????????????????,???????????????????????
?????????????????????????out,???????? - ???C??????????????????????????????????????,???
?????????????,????out??,??????????????
285-3 ???????(?)
?????_???
// Filenamecs_CallOut.sln 1. using System 2.
namespace cs_CallOut 3. 4. class Class1 5.
6. private static void CallOut(out int x,
out int y) 7. 8. int z 9.
x20 10. y30 11. Console.WriteLine
("\n??? ??? x 0 y1
",x,y) 12. zx 13. xy 14.
yz 15. Console.WriteLine ("\n??? ???
x 0 y1 ",x,y) 16. 17.
STAThread 18. static void Main(string
args) 19. 20. Console.WriteLine("\n
Call Out ???? \n")
295-3 ???????(?)
?????_???
21. int a,b 22. Console.WriteLine ("\n????
?????? a ? b ????? ") 23. CallOut(out a, out
b) 24. Console.WriteLine ("\n???? ????????
a 0 b1 ",a,b) 25. Console.ReadLine()
26. 27. 28.
????
305-4 ????????????
- ????????????????,????????????????,??????
????
?????_???
// Filename cs_sendArray1.sln 1. using
System 2. namespace cs_sendArray 3. 4. class
Class1 5. 6. private static int Max(ref int
number) 7. 8. int max number0
9. int tot number.Length 10. for (int
i0 ilttot i) 11. 12. if (numberi
gt max) 13. max numberi
14. 15. return max
315-4 ????????????(?)
?????_???
16. 17. static void Main(string
args) 18. 19. int num new int6
-103, 190, 0, 32, -56, 100 20. int high
num.Length 21. for (int i0 ilthigh
i) 22. Console.WriteLine (numi )
23. int max_num Max(ref num)
//??Max??,????????? 24. Console.WriteLine
("???" max_num.ToString()) 25.
Console.ReadLine() 26. 27. 28.
????
325-5 ????
- ???????(Body)????????????????????,??????
????(Recursive Method)?
??????????
public static long factorial(int n) if (n
0) return 1 return (n
factorial(n-1))
335-6 ????(Overloading)
- ????(Overloading)????????????????????,?
????????????????????,???????????????????????????
?????_???
public static int max(int a, int b)
public static double max(double a , double b
, double c) STAThread static void
Main(string args) int x 6, y 8 double
i 2.33, j 1.55, k 7.55 Console.WriteLine
("???" max(x, y).ToString() )
Console.WriteLine ("???" max(i, j,
k).ToString())
345-7???????????????????
- ????(block level variables)
- ?????????????,???for?switch??????
????????????????????,?????????? ?
?????_???
class Class1 static void Main(string
args) for(int i1 ilt6 i)
//???? Console.WriteLine(i)
Console.WriteLine(i)
355-7???????????????????(?)
- ?. ????(local variables)
- ????????(??)?????????,???????,?????????
,???????????
?????_???
class Class1 private void MyMethod(string
str) string name ??? //???? name
str //???? int k //???? for(int i1
ilt6 i) //???? Console.WriteLine(i)
Console.WriteLine(i)
365-7???????????????????(?)
- ?. ????(static variables)
- ?????????????(???)?????static,?????????
???????(??????)?????????????,?????????????????????
???????????????
???? ???
sbyte,byte,short,ushort,int,uint,long,ulong 0
Char \x0000
Float 0.0f
double 0.0d
decimal 0.0m
bool false
375-7???????????????????(?)
?????_???
- //FileNamecs_staticVar.sln
- 1. using System
- 2. namespace cs_staticVar
- 3.
- 4. class Class1
- 5.
- 6. private static int age 25
- 7. private static string name "???"
- 8. STAThread
- 9. static void Main(string args)
- 10.
- Console.WriteLine("Class1?????????--gt
0????1?\n",name, age.ToString()) - //??Class1?????????--gt?????
??25? - Console.WriteLine("Class2?????????--gt
0???????",Class2.name) - //??Class2?????????--gt??????
???? - 13. Console.ReadLine()
- 14.
- 15.
- 16. class Class2
385-7???????????????????(?)
- ?. ????(?????)
- ?????????(???static???,???????)??,?????
????????Heap?,????????????,???????????????(????)??
??????????????,???????????????????
?????_???
class MyClass public static int vNo
//????,?????? public string vName
//????
395-8 ????
- ?????,??????????????????(run
time)??,???Visual Studio .NET??????(Debug)??,?????
???????????????????????????,??????????????????????
????????(Bug)
- ????
- ??????
- ????
40????
2. ???Debug????
1. ?????break point
3. ?????????????
?????,????-gt??-gt????
415-9 ????
- ??????????????????,?????(Exception)?C?????
???C?Java????????,??????????????????????????????
??,???????,???????? - ?. trycatchfinally??
try try statements //??????? catch
(exception1 e) catchStatements catch
(exception2 e) catchStatements finally
finallyStatements //????????
??,?????????????????????)
425-9 ????(?)
- ?. Exception??
- C ?Exceptions????????,??????????????Ex
ception????,?????System????????????????System.Exce
ption?????????Exception??
? ? ? ?
Exception ?Exception?????????
ArgumentOutOfRangeException ???????????????????????
DivideByZeroException ???0???????
Exception ????????????
IndexOutOfRangeException ?????????????
InvalidCastException ?????????,?????????
OverFlowException ?????????
435-9 ????(?)
? ? ? ?
GetBaseException?? ???????????????
GetObjectData?? ????????????GetObjectData??,??????????????
GetType?? ????????????
HelpLink?? ??????????????
InnerException?? ????????????????
Message?? ??????????
Source ?? ??????????
StackTrace?? ??????????
TargetSite?? ???? (throw) ??????????
ToString?? ??????????????
445-9 ????(?)
?????_???
int a, b, c 0 Console.Write("a ") a
Int32.Parse(Console.ReadLine())
Console.Write("b ") b Int32.Parse(Console.
ReadLine()) try c a / b catch
(Exception e) Console.WriteLine(e)
Console.WriteLine("c " c )
Console.Read()
????
455-9 ????(?)
- ??????-??throw??
- ??????,???????????,???????????????
,throw??????????????,???????????????
?????_???
private static void KeyinMonth(out int
month) Console.Write("???? ( 1 - 12 ) ")
month int.Parse(Console.ReadLine()) if
(month lt 1 month gt 12)
throw new ArgumentOutOfRangeException()
STAThread static void Main(string
args) try KeyinMonth(out month)
catch (ArgumentOutOfRangeException e)
Console.WriteLine("?????\n") catch
(Exception e) Console.WriteLine("?????
\n")
465-10 DateTime?Math?Random??
- DateTime??
- .NET Framework?????DateTime???????
???????????dateTime1???DateTime??????????????,????
??????2002?1?23???4?5?6?7??? - ????DateTime?????
- ????????
- Parse(String s) --- ???yyyy/mm/dd??????
- ToShortDateString() --- ????,??????????
- Day() --- ???????????(?????????????????????)
- DayOfWeek() --- ????????? (????0, ????1)
DateTime dateTime1 new
DateTime(2002,1,23,4,5,6,7)
475-10 DateTime?Math?Random??(?)
- ?. Math??
- .NET Framework?????Math(??)??,?????????
???????????????????
???? ??
Math.Round ??Math.Round(n) ??????n?????,??????????? ??Math.Round(4.5) ????4
Math.Abs ??Math.Abs(n) ??????????????? ??Math.Abs(5.3),????5.3?
Math.Pow ??Math.Pow(x,y) ??????x?y??,?xy? ??Math.Pow(5, 3),????125
485-10 DateTime?Math?Random??(?)
- ?. Random(??)??
- ? .NET Framework???????Random??,????Sys
tem.Random??,?????????????Random???????,????Random
??????????????rnd1???Random????????????? -
- Random??????,?????????????
Random rnd1 new Random()
???? ??
Next ??rnd1.Next() //???????0???,???int?????? rnd1.Next(n1) //??0?n1-1???? rnd1.Next(n1, n2) //??n1?n2-1????
NextDouble ??rnd1.NextDouble() ????0.0?1.0??????
495-10 DateTime?Math?Random??(?)
???1?42????????,????????? _???
//FileNamecs_Random.sln 1. using System 2.
namespace cs_Random 3. 4. class
Class1 5. 6. STAThread 7. static void
Main(string args) 8. 9. //??num??,num0nu
m7????0 10. int num new
int8 11. Random rnd new
Random() //?????? 12. int getData 13. bool
reapeatData 14. int tot 1 15. do 16.
17. getData rnd.Next(1,43) 18. reapeatDat
a false 19. for (int i1 ilttot
i) 20. 21. if(getData numi)
505-10 DateTime?Math?Random??(?)
22. 23. reapeatData true 24. break 25. 2
6. 27. if (reapeatData false) 28.
29. numtot getData 30. tot 31. 32.
while(tot lt 8) 33. Console.WriteLine("???????
????") 34. for (int j1 jltnum.Length-1
j) 35. Console.WriteLine("
?0???1",j.ToString(), numj.ToString()) 36.
Console.WriteLine("?????0",
num7.ToString()) 37. Console.ReadLine()
????