C # language and database "broken-rope"
In the course of my progress. The first phase of the study is the Java Foundation, although now to C # is still the foundation! But!
After a lapse of two months today, again picked up the book to see, the mind of Java in the knowledge of only a few fragments!
so long-term learning experience let me come to a conclusion: if you are not a genius, really is to go through continuous efforts
To reach the point where the world can look
Therefore, the contents of this chapter are purely the small knowledge and minor problems that I have learnt in reality.
hope that the great God of mercy ~. Genius please let the line!
One, the first C # program _ Broken Long rope _!
Analytical:
Start by mentioning it before you begin. The difference between NET and C #
it looks all on the surface. NET and C # belong to Microsoft but there's a difference between them,
So how are we going to analyze their differences?
It is possible to understand:. NET is a platform that allows multiple languages to run on his platform, and C # is a variety
A member of the language!
Next, we'll take you to the backbone of the C # program.
1.namespace keywords
The namespace (namespace) is the way in which code is organized in C #, which works like the package in Java, so we
It is possible to put some tightly related code in the same namespace, which greatly improves the efficiency of management and use.
2.using keywords
Using in Java, if you bring in other packages, you will use the Import keyword, whereas in C #, you use the Used keyword to
Referencing a different namespace
3.class keywords
This is the same as in Java, C # is also an object-oriented language, class represents classes
4.Main () method
This is the same as in Java, is the portal of the program, the application starts from here to run
Note : The first letter of the main () method in C # must be capitalized
The return value of the main () method can be a void or int type, and the main () method can have no arguments.
The main () method in so:c# has four different forms
eg
static void Main (string[] args) {}
Static Intmain (string[] args) {}
static void Main () {}
static int Main () {}
4. Key code
Ma in (0 method adds two lines of code is the key code of this applet, is used for input and output ( must not underestimate him yo ~)
Console.WriteLine (""); Output content from the console
Console.ReadLine (); Entering content from the console
so let's look at the variables and constants in C # next.
Variables: As the name implies, is the amount that can be changed.
Int num=5;
num=7;
Constants ; once defined, its value cannot be modified again in subsequent code.
Parse:PI
Int num=5;
Here's our trick : Massive code folding
Shortcut keys are ctrl+k+s:#region
In C #in the same indispensable class, object and Method!
mentioned the classes and objects believe that we are not strangers
What is a class?
Parsing: A general term for a series of things that have the same properties and behaviors.
Car
Student
Teacher
Person
What is an object?
Parsing: An object is a unique individual that can be found in real life that distinguishes it from other things.
The red Car of Xiao Ming's house
Second, C # Grammar Quick warm-up _ Broken Short Whip _!
Select Structure
C # also has if-else, switch they and Java are the same usage, it is worth mentioning that the use of switch in C #
There is a point of change: In C #, if a case follows a statement, then break is essential!
Eg:
The expression of switch in Java can only be (int/char/constant)
But the value in C # can be (int/char/string)
One-dimensional arrays in C #
What define an array in C #?
eg
The first way
Int[] Arr=new int[]{1,2,3};
The second way
Int[] arr;
Arr=new int[]{1,2,3};
Here's a note: Why do people use the for most instead of the Buddha-foreach code?
Here we explain the limitations of foreach : error when you need to change the values in the array, and for not!
How do I set the array size?
use new to set size: Create An integer array of length 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 the curly braces determines the length of the array
How to get the length of an array (the number of elements in an array)
Answer: the array name . Length
How do I loop through the elements in an array?
loop output array elements
int[] array = new Int[5] {0, 1, 2, 3, 4}; declaring and initializing a one-dimensional array
for (int i = 0; i < array. length;i++)// output all elements in the array
{
Console.WriteLine (Array[i]);
}
iterating through an array element using a foreach loop
A foreach loop is typically used to traverse an entire collection or array
Syntax:foreach ( element type variable name in collection or array name )
{
Statement
}
use of continue and break statements
Continue: End this cycle and continue the next cycle
Break: Ends the current loop
Double Cycle
int I, J; Loop Variable
Outer Loop controls the number of lines printed
for (i = 1; I <= 5; i++)
{
Inner Loop controls the number of printed numbers per line
for (j = 1; J <= I; j + +)
{
Console.Write (j);
}
Console.WriteLine ();
}
Finally teach everyone the best game algorithm- bubble sorting algorithm!
Rule: Each compares adjacent two numbers, the small exchange to the front, each rotation section speed after the maximum number exchange to the last
Using a double loop to achieve bubble sorting
For example:5(n) digits are stored in a one-dimensional array, how to sort
Analysis: How many rounds the outer loop control compares, the cyclic variable i
The inner loop controls how many times each round is compared, and the loop variable J
Observe the law, analyze the relationship between I and J , and finally come to 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 of J and j+1 positions
if the first big, then the small Exchange
}
}
Sincerely thank you to be patient to read, may help is just a little busy, but not really easy!
Hope everyone came here empty-handed!! But when you leave, do not swing the sleeves, do not take away a cloud Oh!
Well! Broken cable really a little difficulty ~ but martial arts cheats this should not be out of the! The average person I don't tell him ~
Well! Take a look at the broken cable steps to know that it will be continuously updated! Many do not say, if you think my small text to you have a bit of help, please pay attention to me!
Crack the long rope, short whip, the tripod, chain gun, chain, fishing nets, flying hammer, Meteor,"and other" soft weapons.
C # language and database Fundamentals