C # Getting Started basic notes

Source: Internet
Author: User

1.1:. NET and c#1.1.1:. NET Overview and C # applications

. NET is a technology located on the Windows platform. Contains all programming that can be run on the. NET framwork platform.

1.1.2:ide Environment

Microsoft exits the powerful platform and technology, and provides a powerful development environment to come and support!!

1.2: The first C # program 1.2.1: Create a new program:

Steps:

1 Start vs Tools

2 New Project

3 Generating an executable file

4 Start Running

1.2.2: Understanding the Console Application file structure

Program.cs: The file is a startup file! The extension is. cs

Hello world. EXE: This file is located in the directory, is the project compiled after the generated file, you can run directly!

1.2.3: Understanding C # Programs

N Namespace: namespaces

N Using: Importing the package's keywords

N class: Name keyword

n Main () method keyword

Variables and constants in the 1.3:c#

Data type:

Common types of data

Java

C#

Example

Integral type

Int

Int

Age

Floating point Type

Float

Float

Results

Double precision

Double

Double

Pi

String

String

String

Name

Boolean

Boolean

bool

Whether the number of families is few

1.3.2: variable declaration rules and constant Declaration rules

1, data type + variable name

2. const data type + constant name

1.4:console class

1.4.1: Output: Console.Write ();

1.4.2: Input: Console.readwrite ();

1.5: Class and Object 1.5.1: Custom method:

Syntax: [access modifier] Return value type method name (parameter list)

{

Method body

}

1.5.2: Understanding Classes and objects:

A class is a template for an object that is an instance of the Class (Programming World: everything Objects)

1.5.3: Notes:

Single line://

Multiple lines:/*

*/

Document comments:///Enter generation format

Folding: #region开始

End: #endregion

1.5.4: Commissioning

shortcut keys:

F5: Start Debugging

SHIFT F5: Stop Debugging

F9: Setting breakpoints or canceling breakpoints

F10: Single Step (skip)

F11: Single-Step entry

Chapter II: C # Fast Grammar warming up2.1: Select structure 2.1.1:IF Select structure

1. Single if: syntax: if (condition)

{

code block

}

2.if (condition)

{

Code 1

}

Else

{

Code 2

}

3.3.if (condition)

{

Code

}

Else if (condition)

{

Code

}

4. Nesting: if (condition)

{

If (condition)

{

Code

}

Else

{

Code

}

}

Else

{

Code

}

L (nesting only if the outer layer is satisfied to continue to perform the inner structure)

2.1.2:SWITCH selection Structure

L The expression for switch of this structure is not required, can be int/double/char/string type

L But there must be a break behind the case (unless there is no content in the middle of the two case).

Syntax: switch (conditional)

{

case constant Expression 1:

Statement

break; must

Case constant Expression 2:

Statement

break; must

Default:

Statement

break; must

}

2.2: Array with loop 2.2.1: one-dimensional array

Square brackets must be behind the data type

Syntax: type [] Array name

    1. Type [] Array name =new type [here can be added without (subscript)] {element 1, element 2, etc. 、、、、、、、、、}

Gets the length: array. Length

2.2.2: Object Array
    • An array of objects is equivalent to creating an array of elements that are composed of multiple objects

U syntax: type [] array name =new type [];

2.2.3: Circular structure 1.while cycle

Syntax: while (expression)

{

code block

}

n First judgment and execution

2.do-while Cycle

Syntax: do

{

Code

}while (condition)

L Execute first, then judge

2. For loop

Syntax: for (expression 1 (initial value), Expression 2 (judging condition), Expression 3 (iteration part))

{

code block

}

L generally used to determine the number of cycles

3. Foreach Loop

Syntax: foreach (element type element variable name in array)

{

Code block general output time is output (element variable name)

}

2.2.4: Jump Statement

Break: Jumps out of the loop body and executes the action behind the Loop body (performs an outer loop) Continue: Ends the loop and resumes the next loop of this loop structure 2.2.5: Double cycle

Definition: The double loop is fairly nested with the loop: The outer loop executes once, and the inner loop executes all!!

2.3: Bubble sort 2.3.1: Bubble sort algorithm

Define an intermediate variable num

For (i=0;i< length -1;i++)

{

For (j=0;j< length-i-1;j++)

{(from small to large) (from largest to smallest)

If (element [j]> element [j+1] or element [j]< element [j+1])

{

num= elements [J]

element [j]= element [j+1]

element [j+1]= Num

}

}

}

Last: Iterate through the array: the sort effect is reached (for)

Formula: N numbers to line up, 22 compared to small front (ascending), outer loop N-1, inner loop n-i-1

Chapter III: Upgrading Mybank3.1:private access modifiers using attributes

Public: Common class, maximum access, highest level!

Private: Proprietary, protected, can only be used inside the class!!

If not written: default internal

3.2:this keywords

This: generally refers to this object, this class of

The effect of the name of the property (field) can be prevented!

Properties in 3.3:c#

The method can be used to ensure data security, you can define a method of the field!

Encapsulate fields with attributes

Syntax: private string _name;

public string Name

{

get{return _name}

Set{_name=value}

}

Properties in 1:c#: Fields in C # are generally private, and if you want to access this field, the implementation of this method of combining fields is called properties by establishing get and set accessors.

Get (Read-only property (available only)): Returns the value for the corresponding private field! (similar to a method) you must return the value of the field with return! Executing a get accessor is equivalent to reading the value of a private field!

Set (write-only property (which can only be set): The accessor is used to set the value of the corresponding private field, similar to the void method. Using an implied argument, (number entered) when the property is assigned, the set accessor is called and the newly assigned value is given to this field!!

2: Data type of attribute: Defines the data type of a class, the data type of the property must be the same as the type of field accessed! (Example: field is int, property is int type)

You can create an object directly after you add parentheses to the property assignment (Student student=new Student () {age=20};)

: 3.4: Value passing and reference passing

Value passing: equivalent to just assigning a copy of the content and then passing it (although the copy can be modified, but changed; there will be no effect on the other side, there is no change to success!! )

Reference passing: (each variable is preceded by a ref (formal parameter and argument)): the equivalent of referencing this content and then modifying the assignment, so that the modification, the true meaning of the modification success!

The fourth chapter: the String class in the String class 4.1:c# of C #

How to handle strings:

Equal

Compare string-specific values for equality

Compare

Compare the size relationships of two strings

Int A=indexof (the character to look for)

Find the coordinates of this character

Int A=lastindexof (the last character to look for)

Find the coordinates of this character

String Join (two strings that need to be concatenated)

Connection string

String[] Split (the object that needs to be split)

Returns an array

Substring (coordinates, coordinates)

The string that intercepts this coordinate interval

String ToLower () string Toupper ()

Convert to lowercase conversion wie uppercase

Trim

Remove spaces and extra characters

L Format formatted

Syntax: string mystring=string.format ("format string", parameter list)

Example: (String. Format ("{0,20}", name)) Name property value: Indicates a width of 20, right-justified

4.2: Type Conversion

Privacy Type conversions: (Automatic type conversion in Java) example: As long as A's value range completely includes the range of B values

You can convert your privacy type

Show type conversions: (Forced conversions in Java): When you want to convert a large range into small, you need to show conversions

Conversions between numeric values and strings:

String to other type

Parse (); Example: Int.parse (console. Readline ())

Other types are converted to strings:

Tostring (); Example: String a=age. Tostring ();

Converting using the Convert class

Convert.ToInt32 ()

Convert to int type

Convert.tosingle ();

Convert to float single-precision floating-point type

Convert.todouble ();

Convert to double-precision floating-point type

Convert.ToString ();

Convert to String type

Constructor (that is, when you create this object, you call a constructor method that is the same as the class name and no return type) before you can create it:

such as StringBuilder stb=new StringBuilder (); (no reference) StringBuilder stb=new StringBuilder (name);

For example: dbo dbo=new dbo (), (without reference) dbo dbo=new dbo (name);

This is also the basic class of StringBuilder, create an object,

In the process of creation, it is called by default to a StringBuilder construction method over there, (just this basic type is not visible on the other side of the method), a construction method

It can also be a parameter, which means that the method is needed to process the following code,

public class StringBuilder or DBO//stringbuilder class

{

1.public StringBuilder (string name) or DBO (string name)//Parameter construction method

{

String newname=name;//processing with parameters

}

2. Public StringBuilder () or dbo ()//non-parametric construction method

{

Where to do the initialization

}

}

(This time also uses the method's overload (same method, the parameter is different))

public class people//another class

{

1.StringBuilder stb=new StringBuilder (name); The equivalent of the public StringBuilder (string name) above is called by default before the object is created.

1. dbo dbo=new dbo (name); (with reference)

2.StringBUilder stb=new StringBUilder (); The equivalent of the public StringBuilder () non-parametric construction method above is called by default before the object is created.

2.DBO dbo=new DBO (); (no reference)

}

C # Getting Started basic notes

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.