C # Fundamentals 01

Source: Internet
Author: User

1. Variable type
int double string char bool decimal
Rules for the use of variables: first declaring and then assigning the last use
int number;
number=10;
number=20;
Console.WriteLine (number);

2. Camel Pascal

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.


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.


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
for (int i=0;i<number. length-1;i++)
{
for (int j=0;j<nums. length-1-i;j++)
{
if (nums[j]>nums[j+1])
{
int TEMP=NUMS[J];
NUMS[J]=NUMS[J+1];
Nums[j+1]=temp;
}
}
}


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.

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

C # Fundamentals 01

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.