C # Notes for quick learning)

Source: Internet
Author: User

The following is an example of how to quickly learn C # through code.

1. Learning any language will surely learn hello, world!

    Main(

2. Original C # Compiler (you can use the following command line to compile C #)

C:>csc HelloWorld.cs

You will get:

HelloWorld

For more information, see: http://sourceforge.net/projects/nant

3. Read files

A: Read the entire file to the string.

   Main( contents = System.IO.File.ReadAllText( +

B: Read all rows from a file to the array.

   Main([] lines = System.IO.File.ReadAllLines( +

C: Row-by-row File Reading without checking errors (very useful for large files)

StreamReader sr =  StreamReader(((line= sr.ReadLine()) != + (sr != )sr.Close();  

4. Write files

A: Write all text in A simple way. (If A file does not exist, it will be created. If it does exist, it will be overwritten. Eventually, the file will be closed)

   Main( myText =  + Environment.NewLine +  +

B: Use Streams to write a line of text to a file.

   =  FileStream(= (sw != 

C: Use using to access the file (when the block is complete, using implicitly calls Dispose (), which also closes the file. The following code is worth noting .)

   ( i = ; i < ; i++ (TextWriter w = File.CreateText( + i +  msg = DateTime.Now +  +

D: "using" as "typedef" (a la "C ")

 RowCollection = List<Node>;

E: difficult way to write a simple XML segment

  writeTree(XmlNode xmlElement, = ( i=;i<level;i+++=    =(XmlAttribute x =++(XmlNode x (x.NodeType == (x.NodeType ==

F: a simple method for writing simple XML fragments

StringWriter stringWriter = = =

G: there must be a default constructor for the object or set written into XML.

   SerializeToXmlString(= =         = 

H: And it must also convert XML into objects.

   DeSerializeFromXmlString(System.Type typeToDeserialize, [] bytes == =           textRepository = ObjectFactory.GetInstance<ITextRepository><BrandAndCode> brandAndCodeList = xml = brandAndCodeList2 = DeSerializeFromXmlString(

I: a few words about the type

The data type generally includes data members and method members, such as int, which includes a value and a method ToString ().

All values in C # Are type instances.

C # provides built-in, or predefined, direct language, which is understood by the compiler and keywords for them. The value types include SBYTE, short integer, long byte, USHORT (unsigned short integer), UINT (unsigned integer), ULONG (unsigned long integer), and floating point number, double-precision floating point number Hu, decimal, Boolean and char (character type ). The predefined reference types are strings and objects. These types are divided into different types and also have aliases in the "System" namespace. For example, the integer int is renamed as System. Int32.

C # the built-in types such as DateTime are also provided in the system namespace. Of course, the compiler cannot directly know these types.

All C # types are classified as follows:

Value Type (Most built-in types, such as int, double, and custom struct, do not have a method that is only worth the enum type)

Reference Type (any class, array, etc)

Generic Type parameter, pointer type

Use a class-defined type

J: Write formated output:

 k = ,k);     Console.WriteLine(,k);      Console.WriteLine(,); Console.WriteLine(,);Console.WriteLine(,k);      Console.WriteLine(,k);    Console.WriteLine( .ToString()); 

K: namespace (namespace is used to reduce confusion)

 Monkeys = MyZoo { Monkeys.Howler; }

L: use String. Format () to convert decimals to strings.

s.Append(String.Format(,*completes/count));

Or use the ToString () method on the double Object:

s.Append(myDouble.ToString()

Or

String.Format(,.OnTrack)

M: format the DateTime object.

DateTime.Now.ToString(); 

5. Examples of constructor, static constructor, and destructor:

  Test2() {               i = ~Test2() {        Console.Out.WriteLine(  Main(

Run:

inside ==

 

Related Article

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.