Consolidate the just-learned C # during the holidays and save some small examples to record this process!
Under vs (I used 08) -- create a project -- C # console application, and then copy it and press F5 to view the result ~ I hope it will be helpful for beginners who are new to C ~
Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
/* Declare the string */
String STR = "jyml. W ";
String str2 = "C #";
String str3 = "programmer ";
String str4 = "Beijing, London, Washington, Paris, Toronto ";
/* Basic Array Operations */
String [] groups = {"Asp.net", "C #", "MVC", "WCF", "WPF", "LINQ"}; // array Initialization
Int COUNT = groups. length; // obtain the array length.
Console. writeline ("---------------- array bytes length -------------------");
Console. writeline (count. tostring (); // outputs the obtained array Length
Console. writeline ("---------------- original array element value -------------------");
For (INT I = 0; I <count; I ++) // traverses the Array
{
Console. writeline (groups [I]); // outputs each element in the array one by one
};
/* Basic string operations */
Console. writeline ("Hello! I'm {0}, let's learn {1} 2 gether! ", STR, str2); // format multiple strings
If (STR = str2) // string comparison method (1) -- use "=" to compare
{
Console. writeline ("Equal string length (^ 0 ^) y ");
}
Else
{
Console. writeline ("String Length not equal to (TOT )");
}
If (Str. compareto (str2)> 0) // string comparison method (2) -- use the "Compare" method to compare
{
Console. writeline ("String Length not equal to (TOT )");
}
Else
{
Console. writeline ("Equal string length (^ 0 ^) y ");
}
Console. writeline (STR + "is a" + str2 + "" + str3); // string connection
Console. writeline (str4.toupper (); // String Conversion _ uppercase
Console. writeline (str4.tolower (); // converts string to lowercase
String [] P = str4.split (','); // string split -- use the "split" method to split the string and store it in the array P
For (INT I = 0; I <p. length; I ++) // traverse P
{
Console. writeline (P [I]);
}
If (string. isnullorempty (str4) // whether the string is null-use the static method of the string class
{
Console. writeline ("the string is null! ");
}
Else
{
Console. writeline ("the string is not empty! ");
}
Str4 = str4.replace ("Washington", "challenge t"); // string replacement-use the "replace" Method
Console. writeline (str4 );
Console. readkey (); // wait for the user to enter
}
}
}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/japril1988/archive/2010/01/24/5250602.aspx