C # and. NE Study day Sixth

Source: Internet
Author: User

Absrtact: (mainly is the Zhaojianyu of the wisdom of the podcast of the teacher class notes oneself in Add a little own understanding, here Thanks Zhaojianyu teacher)

1. Variable type
int double string char bool decimal
Rules for the use of variables: first declaring and then assigning the last use

1 int Number ; 2 number=; 3 number=; 4 Console.WriteLine (number);

2. Camel Pascal

Camel:

Used primarily for the naming of variables

Camel-style nomenclature is when a variable name or function name is a unique identifier consisting of one or more words, the first word starts with a lowercase letter, the first letter of the second word is capitalized, or the first letter of each word is in uppercase letters, for example: MyFirstName, Mylastname, Such variable names look like camel peaks, so they get their name.

Pascal:

Used primarily for the naming of functions and method classes

The word is not separated by a space break or a connection number (-), the bottom line (_), the first letter is capitalized, and the first letter of the subsequent word is also capitalized, for example: FirstName, LastName. The initials of each word are named in uppercase letters, known as the Pascal Nomenclature, and are derived from the naming conventions of the Pascal language, also known as the "big hump-type nomenclature" (Upper Camel case), a subset of camel-cased.

3. Operators
Assignment operator: =
Compound assignment operator: + = = *=/=%= sum+=age; Sum=sum+age;
Arithmetic operator: +-*/% + +--
Relational operators: > < >= <= = = =!
Logical operators: && | | !

4. Syntax structure in C #
Branching structure:
If If-else
Select structure:
While do-while for


5. Constants
Syntax for declared constants:
Const variable type variable name = value;
When will the constants be used?

6. Enumeration
Grammar:
[public] enum enum name
{
Value of 1,
Value of 2,
Value of 3,
........
}
Public: Access modifier. Public, accessible to all.
Enum: keyword that declares the keyword of an enumeration
Enumeration name: To conform to the Pascal naming convention

The enumeration is declared below the namespace, outside of the class, indicating that all classes can use this enumeration.

An enumeration is a variable type that int--double a string decimal.
Just enumeration declarations, assignments, and usage are not the same as those of ordinary variable types.


We can convert a variable of an enumeration type to an int type and a string type.
Enum types are mutually compatible with int types by default, so you can convert the syntax of type conversions to each other.
When you convert a value that is not in an enumeration, the exception is not thrown, but the number is displayed directly.

Enumerations can also be converted to and from string types, and if you convert an enumeration type to a string type, you call ToString () directly.
If you convert a string to an enumeration type, you need a line of code such as the following:
(enum type to convert) Enum.parse (typeof (enum type to convert), "string to convert");
If the converted string is a number, it will not throw an exception even if it is not in the enumeration.
If the converted string is text, an exception is thrown if it is not in the enumeration.
Instance:
public enum Gender
{
Man
Woman
}
Use:
Gender Gender = Gender. Male;
Note: The element in the last enumeration can be added, or it can be added without

Enum type conversions

7. All types can be converted to a string type, calling ToString ().


8. Structure
Can help us declare multiple variables of different types at once.
Grammar:
[public] struct struct name
{
Member;//Field
}
A variable can store only one value during a program run, and a field may store multiple values.

Add _ Line Before field


9. Arrays
Store multiple variables of the same type at once.
Grammar:
Array type [] array name =new array type [array length];

Once the length of the array is fixed, it can no longer be changed.

10. Bubble sort: The elements in an array are arranged in order from large to small or from small to large.
Int[] nums={9,8,7,6,5,4,3,2,1,0}; 0 1 2 3 4 5 6 7 8 9
First trip Comparison: 8 7 6 5 4 3 2 1 0 9 exchanged 9 times i=0 J=nums. Length-1-i
Second trip comparison: 7 6 5 4 3 2 1 0 8 9 exchanged 8 times I=1 j=nums. Length-1-i
Third Trip Comparison: 6 5 4 3 2 1 0 7 8 9 exchanged 7 times i=2 J=nums. Length-1-i
Four-time Comparison: 5 4 3 2 1 0 6 7 8 9 exchanged 6 times i=3 j=nums. Length-1-i
V Comparison: 4 3 2 1 0 5 6 7 8 9 swapped 5 times
Six-time Comparison: 3 2 1 0 4 5 6 7 8 9 exchanged 4 times
Seventh trip Comparison: 2 1 0 3 4 5 6 7 8 9 swapped 3 times
Eighth trip Comparison: 1 0 2 3 4 5 6 7 8 9 swapped 2 times
Nineth Trip Comparison: 0 1 2 3 4 5 6 7 8 9 swapped 1 times

1  for(intI=0; I<number. length-1; i++)2 {3  for(intj=0; J<nums. length-1-i;j++)4 {5 if(nums[j]>nums[j+1])6 {7 inttemp=Nums[j];8nums[j]=nums[j+1];9nums[j+1]=temp;Ten } One } A}

int array default 0
BOOL Array Default Flase
String default is NULL
Several ways to declare an array:

1 1、int[]a =New int[Ten];2 2、int[]a = {1,2,3,4,5,6,7,8,9,Ten};3 3、int[]a =New int[Ten]{1,2,3,4,5,6,7,8,9,Ten};4 4、int[]a =New int[]{1,2,3,4,5,6,7,8,9,Ten};

11. Methods
A function is a mechanism for reusing a heap of code.
Syntax for the function:
[public] static return value type method name ([parameter list])
{
Method body;
}
Public: access modifiers, public, common, and accessible.
Static: Statically
Return value type: write void if no write return value is required
Method Name: Pascal The first letter of each word is larger. Remaining Letters lowercase
Parameter list: The conditions that must be provided to this method in order to complete this method. If there are no arguments, the parentheses cannot be omitted.

When the method is written, it must be called in the main () function if it wants to be executed.
Method's invocation syntax:
Class name. Method name ([parameter]);
In some cases, the class name can be omitted, if you write the method with the main () function in a class, this time,
The class name can be omitted.

Cases:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceConsoleApplication78 {9     class ProgramTen     { One         Static voidMain (string[] args) A         { -             intA = Getmax (3,6); - Console.WriteLine (a); the Console.readkey (); -         } -         /// <summary> -         ///calculates the maximum value for the number of two int types +         /// </summary> -         /// <param name= "N1" >First integer</param> +         /// <param name= "N2" >a second integer</param> A         /// <returns>returns the largest integer in a two-digit number</returns> at          Public Static intGetmax (intN1,intn2) -         { -             returnN1 > N2?n1:n2; -         } -     } -}
Code

12. Return
1. Returns the value to return in the method.
2. End this method immediately.

C # and. NE Study day Sixth

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.