C # fifth Day

Source: Internet
Author: User

Reference namespace shortcut key: Shift + Alt +f10;

Value types and reference types:

Difference:

1, value types and reference types are not stored in the same place in memory;

2, when passing value types and passing reference types, the way they are passed is different. Value types We call value passing, reference types we call reference passing.
We learn the value types and reference types:
Value types: int, double, bool, char, decimal, struct, enum reference type: string, custom class, array
Storage: Values of value types are stored in the stack of memory. The value of a reference type is stored in the heap of memory.

3. String
1), the immutability of the string
When you re-assign a string, the previous value is not destroyed, but the new value is re-opened in a space.

When the program finishes, the GC scans the entire memory and destroys it immediately if it finds that the space is not pointing.

2), we can say the string as a char type of a read-only group.
ToCharArray (); Convert a string to a char array
New String (char[] CHS): Ability to convert a char array to a string

4. The various methods provided by the string
1), Length: Gets the number of characters in the current string
2), ToUpper (): Convert characters to uppercase
3), ToLower (): Convert string to lowercase
4), Equals (lessontwo,stringcomparison.ordinalignorecase): Compares two strings, can ignore the case
5), Split (): Splits the string and returns an array of string types.

            //Convert Date string (2008-05-16) to May 16, 2008 format            strings ="2008-05-16"; string[] Date=s.split (New Char[]{'-'}, Stringsplitoptions.removeemptyentries); Console.WriteLine ("{0} year {1} month {2} days", date[0],date[1],date[2]); Console.readkey ();

6), Substring (): resolves the string. Include the position to intercept at the time of interception.
7), IndexOf (): Determines where a string appears for the first time in a string, if no return-1, value type, and reference type are stored in memory.

1 get the folder name in the disk2             stringPath =@"e:\c# Hu's Intelligence podcast. NET College \net Basic set of video Tutorials version 2014--03c# Advanced \02--Object-oriented inheritance \ Special. NET Basics Full Video Tutorial version 2014 (Tenth day) \video";3             intindex = path. LastIndexOf ("\\");4             stringName=path. Substring (Index +1);5 Console.WriteLine (name);6Console.readkey ();

8), LastIndexOf (): Determine the last occurrence of a string in the string, if not the same return-1
9), StartsWith (): Judging by .... Begin
10), EndsWith (): Judging by ... End
11), replace (): Replace a string in a string with a new string
12), Contains (): Determines whether a string contains the specified string
13), Trim (): Remove the space before and after the string
14), TrimEnd (): Remove the trailing space in the string
15), TrimStart (): Remove the preceding space in the string
16), String. IsNullOrEmpty (): Determines whether a string is empty or null
17), String. Join (): The array is concatenated with the specified string, returning a string.

1             string[] names = {"Zhang San","John Doe","Harry","Tease Show","Zhao Liu" };2             stringStrnew =string. Join ("__", names);3 Console.WriteLine (strnew);4Console.readkey ();

C # fifth Day

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.