C # Basic Article 03

Source: Internet
Author: User

1: Whether it is an argument or a formal parameter, it opens up space in memory.

2: Write a method, its function must be single, the most taboo in the method is to appear prompt user input words. 3:out ParametersIf you return more than one type of value in a method, consider returning an array. However, if you return multiple values of different types, it is not possible to return an array, we can consider using out parameters. The out parameter focuses on returning several different types of values in a method. 4:ref parameters (similar to pointers in C, or references in C + +)The ability to take a variable into a method to change, after the change is complete, and then take the changed value out. The 5:params parameter (except that the params does not need to be written in the argument list, but the out and ref keywords must be written)The elements of the argument list that are consistent with the variable parameter array type are treated as elements of the array. the params variable parameter must be the last element in the argument list. 6: Overloading of methodsthe overloads of a method refer to the same method name, but with different parameters, it is not related to the return value of the method. The parameters may be different in number or different in type. Keep several decimals (two decimal places): 7: string s=num. ToString ("0.00");num=convert.todouble (s);this will keep num two decimal places. of course, can also be used in the form of placeholders, but also to achieve the effect!!!   8:the nature of the property is two methods, one called Get (), and one called set ().when setting the value limit, the parameter is Vlaue, and the parameter is the field when the value is qualified. The property has a readable writable property, a read-only property, and a write-only property. Fields FieldMethods MethodProperty//properties9:This keyword1), object representing the current class2), the constructor for calling this class, shown in the class: this 10: Name Spaceyou can think of a class as belonging to a namespace. If there is no namespace for this class in the current project, we need to manually import the namespace where the class is located. 1, with the mouse to point;2, ALT+SHIFT+F10;3, remember the name space, manual to refer to; 11: A class that references another project in one project1, add the reference;2, the reference namespace; 12: Differences between value types and reference types1. Value types and reference types are not stored in memory;2, when passing value types and reference types, the delivery method is different; (value passing, reference passing) 13: Learned value types and reference typesvalue type: int double char decimal enum struct BOOLReference type: string array custom classvalue types are stored in the stack of memory;The reference type is stored in the heap of memory; 14: String1, non-denaturedwhen you re-assign a string, the old value is not destroyed, but a new space is re-opened to store the value;when the program is finished, the GC scans the entire memory and destroys the space if it finds that some space is not pointed .2. We can treat a string as a read-only group of type char. ToCharArray (); Converts a string into a char array;new String (char [] CHS), capable of converting a char array to a string; 15: Common Methods of strings1, length, gets the number of characters in the current string or the array length;2, ToUpper (), convert the string to uppercase; (return value string)3, ToLower (), convert the string to the form of small Xie; (return value string)4, Equals (S2, StringComparison.OrdinalIgnoreCase) compares two strings, can ignore the case of the string; (return value bool)5, Split (), splits the string, returns an array of type string, (return value string[])6, SubString (), intercept the string, at the time of interception contains the location to intercept, (there are two different parameters--int--int-length) (return value string)7, IndexOf (), determine which character is the first occurrence of a string, if not, return-1, the value type and reference type are not stored in the same place in memory. (return value int)8, LastIndexOf (), determine which character in the string last occurrence of the position, if not, the same return-1; (return value int)9. StartsWith (), judging by ... Start; (return value bool)10. EndsWith (), judging by ... End; (return value bool)11, replace (), replace a string in the string with a new string; (return value is String)12, Contains (), to determine whether a string contains a string; (The return value is bool)13, Trim (), remove the space before and after the string; (return value string)14, TrimEnd (), remove the trailing space in the string; (return value string)15, TrimStart (), remove the string header space; (return value string)16, String. IsNullOrEmpty () to determine whether a string is null or empty; (return value bool)17, String. Join (), which joins the array according to the specified string, returning a string. (return value string) 18: Inheritance1), a subclass inherits the properties and methods of the parent class, but does not inherit the parent class's private fields and constructors, although it does not inherit the parent class's constructor, but the subclass defaults to calling the parent class's parameterless constructor and then creating the parent class object to make it easier for the subclass object to invoke the parent class's method. (This is all a prerequisite)2), call the constructor of the parent class in the subclass remember to use the base () keyword. 3), the role of the New keyword:Create objects;hiding a member of the same name inherited from the parent class, the hidden consequence is that the subclass cannot call a member of the same name as the parent class.  19:arraylist list=new ArrayList ();add a single element with list. Add ();add a set of words with list. AddRange ();To Delete an element:list. Clear ();//Delete all elementslist. Remove (object obj);//delete specific elements, obj write who, just delete wholist. RemoveAt (int dex);//drop specific element by subscriptlist. RemoveRange (int dex,int long);//starting from Dex this subscript deletes elements of long lengthList.sort ();//ascending orderlist. Reverse ();//Invert elementlist. Insert (); Inserts an element at a specified locationlist. Insertrange ();//Insert a collection at the specified locationlist. Contains (); Determine if an element is included :is: Represents a type conversion and returns a true if the conversion succeeds, otherwise a false is returned. As : Represents a type conversion, and returns a null if it is able to convert to return the corresponding object.  21: When we output an object to the console, we output the namespace where the class is located by default. Similarly, when you output an array to the console, the namespace in which the array type resides is output by default. For Example:int[] number={1,2,3,4,5,6,7,8};Console.WriteLine (number);//The console will only output system.int32[at this time] length issues for 22:arraylist collectionswhen the number of elements actually contained in the collection (count) exceeds the number of elements that can be contained (capacity),The collection will open up to one more space in memory to ensure that the length of the collection is always sufficient!    23:hashtable: Set of key-value pairsThe value is stored according to the key, and the key is unique and cannot be duplicated. Hashtable ht = new Hashtable ();There are two ways to add elements:1:ht. ADD (Keys,value); The value of keys cannot be duplicated;2:ht[keys]=value; This is similar to assignment, where the value of keys is the same, overwriting the previous old values. when iterating over elements in a Hashtable, only the Foreach loop is used, and the For loop does not meet the requirements. foreach (var item in collection)//var: The ability to infer the type of the value based on the value (however, the Var type is always used because the variable must be initialized when the variable is defined with Var){//c# is a strongly typed language (the explicit type definition of the variable must be given)XXXXX ...//js is a weakly typed language (no explicit type definition is required for a variable)}when traversing the Hashtable collection, the values can be traversed according to the key, or they can be traversed directly according to the values. foreach (Var item in HT. Keys)//by Key to traverseforeach (Var item in HT. Value)//traverse by value directlythere is no requirement for the type of key and value in the Hashtable collection, which can be any type:For example: Ht. ADD ("abc", "CBA"), Ht. ADD (' A ', false), Ht. ADD (true,3.45) .....Common methods in Hashtable:ht. ADD (); adding elementsht. Remove (Keys); Key value to remove elementsht. Clear (); Remove all elementsht. Containskeys (Keys); Determine if a key value is included keysht. Containsvlaue (Value); Determine if a value is included

C # Basic Article 03

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.