C # language and database basics,
C # "cable breaking" for languages and databases"
In my course progress, the first phase is the basis of Java, although now C # is still the basis! But!
Today, two months later, I picked up my books and found that my mind has only a few pieces of knowledge about Java!
So's long-term learning experience has led me to draw a conclusion: if you are not a genius, it is indeed a constant effort.
In order to make the world look up to the point ~
Therefore, the content of this chapter is purely a small knowledge and a small problem I have learned in reality.
Hope the gods are cool ~. Just give up!
I. The first C # program _ broken cable _!
Resolution:
Before getting started, let's take a look at the differences between. Net and C #.
On the surface, it seems that both. Net and C # belong to Microsoft, but there are still some differences between them,
So how can we analyze their differences?
It can be understood as follows:. Net is a platform on which multiple languages can be run, while C # Is a variety
A member of the language!
Next, let's take you to know the main idea of the C # program.
1. namespace keywords
Namespace (namespace) is the way to organize code in C #. Its function is similar to package in Java, so we can
You can put closely related code in the same namespace, greatly improving management and usage efficiency.
2. using Keyword
In Java, if you include other packages, you will use the import keyword. in C #, the using keyword is used.
Reference Other Namespaces
3. class keywords
This is the same as in Java. C # is also an object-oriented language, and class represents the class.
4. Main () method
This is the same as in Java. It is the entry of the program, where the application starts to run.
Note: The first letter of the Main () method in C # Must be capitalized.
The Return Value of the Main () method can be void or int type. The Main () method can have no parameter,
The Main () method in so: C # has four forms.
Eg:
Static void Main (string [] args ){}
Static intMain (string [] args ){}
Static void Main (){}
Static int Main (){}
4. key code
Main (the two lines of code added in the 0 method are the key code of this applet, which is used for input and output (do not underestimate it ~)
Console. WriteLine (""); // output content from the Console
Console. ReadLine (); // enter content from the Console
Next let's take a look at the variables and constants in C #.
Variable: As the name implies, it is a variable that can be changed.
Int num = 5;
Num = 7;
Constant. Once defined, its value cannot be modified in subsequent code.
Resolution: PI
Int num = 5;
Here we mention ourTrick: Massive code folding
The shortcut key is Ctrl + K + S: # region
In C #, there are no classes, objects and methods!
I believe everyone will be familiar with classes and objects.
What is a class?
Resolution: A group of things with the same attributes and behaviors.
Car
Student
Teacher
Person
What is an object?
Analysis: an object is a unique individual that can be found in real life and be different from other things.
Xiaoming's red car
II. C # Quick syntax warm-up _!
Select Structure
In C #, if-else and switch are both in the same usage as Java. It is worth mentioning that switch is used in C #.
With some changes: in C #, break is essential as long as a statement follows after case!
Eg:
In Java, the switch expression can only be set to (int/char/constant)
However, the value in C # Can Be (int/char/string)
One-dimensional array in C #
How to define an array in C?
Eg:
// Method 1
Int [] arr = new int [] {1, 2, 3 };
// Method 2
Int [] arr;
Arr = new int [] {1, 2, 3 };
Here I will mention: Why do we use the most for encoding instead of forforeach?
Here we will explain the limitations of foreach: When you need to change the value of the array, an error will be reported, but for will not!
How to set the array size?
Use new to set the size: Create an integer array with a length of 5
Int [] array = new int [5];
Array initialization:
Int [] arr = new int [5] {0, 1, 2, 3, 4 };
Int [] arr = new int [] {0, 1, 2, 3, 4}; // omit Length
Int [] arr = {0, 1, 2, 3, 4}; // omit new
[5] -- the number in square brackets determines the length of the array.
{0, 1, 2, 3, 4} -- the number of elements in braces determines the length of the array.
How to get the length of the array (number of elements in the array)
Answer: array name. Length
How to cyclically output elements in an array?
// Cyclically output array elements
Int [] array = new int [5] {0, 1, 2, 3, 4}; // declare and initialize a one-dimensional array
For (int I = 0; I <array. Length; I ++) // output all elements in the array
{
Console. WriteLine (array [I]);
}
Use foreach to traverse array elements cyclically
A foreach loop is generally used to traverse the entire set or array.
Syntax: foreach (element type variable name in set or array name)
{
// Statement
}
Use of the continue and break statements
Continue: end this loop and continue the next loop
Break: ends the current loop
Dual Loop
Int I, j; // cyclic variable
// Controls the number of rows printed in the outer loop
For (I = 1; I <= 5; I ++)
{
// The number of numbers printed per line is controlled cyclically in the inner layer
For (j = 1; j <= I; j ++)
{
Console. Write (j );
}
Console. WriteLine ();
}
Finally, I will teach you the most interesting algorithm-the Bubble Sorting Algorithm!
Rule: compare two adjacent numbers each time, small switches to the front, and the maximum number after each wheel speed switches to the end
Use double loop to Implement Bubble Sorting
For example, how to sort 5 (n) numbers stored in a one-dimensional array
Analysis: How many rounds are compared in the outer loop control, and the cyclic variable I
The number of times each round is compared in the inner loop control. The cyclic variable j
Observe the law, analyze the relationship between I and j, and draw a conclusion.
I = n-1, j = n-1-i
The code framework is as follows:
For (I = 0; I <n-1; I ++)
{
For (j = 0; j <n-1-i; j ++)
{
// Compare elements at the position of j and j + 1
// If the front is large, the back is small.
}
}
Thank you very much for your patience. It may be a little busy, but it is really not easy!
I hope everyone will be here empty-handed !! However, when you leave, do not wave your sleeves or take away a cloud color!
Well! It is a little difficult to break the cable ~ However, the secret of Martial Arts shouldn't be passed out! I will not tell the average person ~
Well! Take a look at the broken-line step and you will know that it will be continuously updated! If you think my Xiaowen is helpful to you, please pay attention to me!
Crack long cable, short whip, three sticks, chain gun, tie chain, fishing net, Flying Hammer, meteor,"Wait"Soft weapons.