C # Basic Notes

Source: Internet
Author: User

The first chapter:


1.c# basic structure for creating programs

Class name

{  staticvoid Main (string[]args)  {   }}

Attention:
1) namespace
2) using
3) class name naming rules: Letters, numbers, _ composition numbers cannot start with a key letter uppercase
4) Main4 species
static void Main () {}
static int Main () {}
static void Main (string []args) {}
static int Main (String[]args) {}

2.c# Data types
Basic:
Int
Double
Char
bool
Float
Reference:
String
Array
Class

3.c# Defining variables

int a=ten; int a;a=ten;

4. Constant definition
const int a=3.14;
Note: Constants are not allowed to be modified once they are defined

5.c# output data to console: Console.WriteLine (); Write ();
Received data: Console.ReadLine ();

6.c# method definition
Public/private return value type method name (parameter list)
{
Subject
}

7. Classes and objects
Members of the Class: field (Private), property (public), method (public)

classstudent{Private intAge ;  Public intAge {Get{returnAge ;} Set{if(value<0) {age= -;}Else{age=value;}} }    Public voidStudy () {}} Student a=NewStudent (); A.age=9; A. Study ();

8. Notes
There are three types of comments in C #, one line://multi-line/*/document///

9. Debug: F9 Set breakpoints F5 start debugging




Chapter II:
1.c# operator
1) Assigned value =
2) Logic && | | !
3) Relationship > < = = >= <=! =
4) Arithmetic +-*/% + +--
5) conditions? :
6) Composite (assigned value) + = = *= Sum=sum+i; Sum+=i;
2.c# Branching Structure
1) Basic: if () {}else{}
2) Nested: if () {if () {}else{}}else{if () {}else{}}
3) Multiplicity: if () {}else if () {}else if () {}....else{}
4) Switch:
switch (expression intar/string)
{        case  constant:             statement;             break;        ......         default : a             statement             ;break;}


3. Loop structure:
1) while () {}

2) do{}while ();

3) for (expression 1; expression 2; expression 3) {}

4) foreach (data type variable name in array/collection) {}


4. Arrays:
1)int[]a; A=New int[5];2)int[]a={2,3}; int[]a=New int[]{2,3}; int[]a=New int[2]{2,3};3)int[]a=New int[5];


5. Bubble sort
Outer: N-1
Lining: n-1-i
int[]a={ the, A, About,3, the}; for(intI=0; i<a.length-1; i++)//Wheel{   for(intj=0; j<a.length-1-I.; J + +)//number of comparisons per round  {        //Compare Swap        if(a[j]>a[j+1])        {                inttemp=A[j]; A[J]=a[j+1]; A[j+1]=temp; }  }}

Example: int [] nums = {5,9,8,6,89};  Using bubble sort, how many times will it compare? 10 plays
Chapter III:
1. Access modifiers:
Private can have a class of internal can be used, the access level is the lowest. Public
1. Characteristics of value types and reference types that are passed as parameters of a method
Value passing: deformation is not changed
Reference passing: Deformation is also changed (except string)

The Fourth chapter:
1.string class method
strings="Hello Hello";strings1=" How is You";1) SubString () s.substring (2,3) S.substring (1);2) IndexOf () S.indexof ('e') S.indexof ("ll");3) LastIndexOf ()4) Join ()stringStr=string. Join ("**", arr); how**are** You5) Equals ()6) ToLower ()7) ToUpper ()8) Trim ()9) Split ()string[]arr=s1. Split (' '); Ten) Compare ()intR=string. Compare (S,S1);(1/-1/0) One) Format ()strings=string. Fromat ("format string", parameter list);

2. Data type Conversion


1.string---> Value xxx. Parse (); Note that the value in parse must be a string type,
And is the type that can be correctly converted to the corresponding numeric value. For example: int a = Int. Parse ("1.5"); Run-time error
Value---->string toString ();


2. Value----Value
Display conversion: int a= (int) 5.6;
Implicit conversions: double-d=10;

3. Any---
XXX c=convert.toxxx (variable);


***************************************************************************
Database Section *************************
***************************************************************************


Basic additions and deletions to check grammar
-------------------------
1. Inserting the syntax structure
1) Single-line insertion
Insert into table name (column name)
VALUES (value)

2) Insert with Union multiple rows
Insert into table name (column name)
Select Value Union
Select Value .....
Select value

3) New table does not exist
Select Old table column name
into new table name
From old table name

4) New Table exists
Insert into new table name
Select Old table column name
From old table name


2. Delete
Delete from table name where condition
TRUNCATE TABLE name

3. Modifications
Update table name set column name = new value WHERE condition

4. Enquiry
Select Column Name
From table name
Where condition
GROUP by group column name
Having filter conditions
Order by sort column name desc

Database Connection Section
---------------------

Database connection steps:

First, create the DBHelper class

1. Create a connection string

Static string constr=@ "server=.; Database=myschool;uid=sa;pwd=sa; ";
Private StaticSqlConnection con; Public StaticSqlConnection con{Get        {                if(con==NULL) {con=NewSqlConnection (CONSTR); Con.                Open (); }                Else if(Con. state==System.Data.ConnectionSate.Closed) {con.                Open (); }        returncon; }}

Second, the method

1.ADO. NET's two important components
. NET Framework Data Providers
DataSet Data Set

4 Core objects of the 2..NET framework Data Provider
Connection: Connecting to a Database
Command: Execute commands (SQL statement)
DataReader: Reading data from a data source
DataAdapter

1. Building SQL statements
String sql=string. Fromat ("",);

2. Create a Command object
SqlCommand cmd=new Sqlcmmand (Sql,dbhelper.con);

3. Calling methods
1) Query single value: XXX c=convert.toxxx (cmd). ExecuteScalar ());
2) Insert/update/delete:int R=cmd. ExecuteNonQuery ();
3) Querying large amounts of data:
SqlDataReader Sdr=cmd. ExecuteReader ();
while (SDR. Read ())
{
sdr["column name"];
SDR[0]
}
Sdr. Close ();

4. Close the database connection
DBHelper.Con.Close ();


5. Exception Handling
try{} catch () {} fianly{}

Share from http://bbs.ichunqiu.com/thread-7131-1-1.html

C # 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.