[Language] C # Travel _ ① _ brief variable rules

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.