Three. String Patchwork StringBuilder
StringBuilder sb= New StringBuilder ();
Sb.append ("AAA");
Sb.append ("bbbb");
Console.WriteLine (Sb.tostring ());
Four. Traverse
string [] astring={"AAA", "BBB", "CCCC", "dddd"};
foreach (Var a in astring)
{
Console.WriteLine (c);
}
Five. Error, exception
The 5.1 error is a grammatical problem and cannot be compiled.
Exceptions can be compiled but not run correctly.
5.2 Resolving exceptions
Try
{The code to which the exception occurred
}
catch (Exception type, exception object name)
{The code being processed
}
Finaly
{The code to execute regardless of whether an exception occurred
}
Try
{
String[] astring = {"AAA", "CCC", "dddd", "eeeeee"};
Console.WriteLine (Astring[5]);
}
catch (Exception ex)
{
Console.WriteLine (ex. message);//Print out exception information
Console.WriteLine ("The website is under repair ...");
}
----------------Array
I. One-dimensional arrays
Disclaimer: int[] a={1,2,3}//Common
Int[] A=new int[3]; a[0]=1;a[1]=2;
Int[] a =new int[3]{1,2,3}; [3] 3 of the inside can be omitted
Two. Two-dimensional array
Statement: int[,]a={{1,2},{2,3},{3,4}};
Int[,]a=new int[3,2];a[0,0]=1;//a Row One column 1
int[,] i = new int[3,2] {{1, 2}, {1, 1}, {2, 3}};//[3,2] The array cannot be saved
Three. Adding and removing array elements (arrylist)
3.1 is a collection that is used to store data, to import the System.Collections namespace when used
The size of the arrylist can be dynamically increased as required
3.2 object is the parent class of any data type
int[] i = new int[] {1, 2, 3, 4};
ArrayList List = new ArrayList ();
foreach (Var a in i)
{
List.add (a);//Add A to List
}
List.removeat (0);//Delete First element
List.add (0);//Add 0 at the end of the list
List.insert (1, 5);//Insert 5 at index value 1
List.clear ();//Clear all existing elements
foreach (var b in List)
{
Console.Write (b);
}
The generic form of 3.3 ArrayList list<t>
int [] anumber={2,23,23,45,67,5,2}
List<int> list=new list<int> ();
foreach (Var a in anumber)
{
List. Add (a);
}
3.4 Hashtable
Hashtable ht = new Hashtable ();
Ht. ADD ("Key1", "AAAA");
Ht. ADD ("Key2", "CCCC");
foreach (Var key in Ht. Keys)
{
Console.WriteLine (Ht[key]);
}
The generic form of 3.5 hashtable dictionary
Traversal of Dictrionary
dictionary<string, string> dt = new dictionary<string, string> ();
Dt. ADD ("Key1", "daaa");
Dt. ADD ("Key2", "ddddd");
foreach (var key in dt.) Keys)
{
Console.WriteLine (Dt[key]);
}
Four. Encapsulation
Public all files in the current namespace can be called across assemblies (another new class library created) for all files
Protect internal all the files under the current namespace, as well as the cross-assembly subclasses inside
Internal all the files under the current namespace. (For a class, the default access modifier is internal)
Protect in this class or its subclasses, or in subclasses of a cross-assembly
Private can only be used within this class. (variable, method default access modifier is private)
2015-10-27 c#3