Quick review of C # Basics (tips for programming) to be perfected

Source: Internet
Author: User

One, type conversion

Two, variable parameters

Three, string

Iv. Delegation

Five, the constructor function

Vi. Expressions of Lamba

Vii. Linq

Viii. Entity Framework

1. Entry of the program: entities file suffix Context.cs

2. The database information is generated in a class corresponding to the database table in the file database name. The name of the table in TT (the name of the general EF is the same as the name of the database or the name of the project plus db)

3.EF database for deletion and modification

Increase:

Testentities entities = new testentities ();
User user = new user ();
User. Id = 1;
User. UserName = "Shine";

Entities. Users.add (user);
Entities. SaveChanges ();

Inquire:

var users = entities. Users.tolist ();

Delete

Entities. SaveChanges ();
var users = entities. Users.tolist ();
foreach (Var u in users)
{
Entities. Users.remove (U);

}
Entities. SaveChanges ();

Modify

var user2 = entities. Users.firstordefault (U = u.id = = 1);
if (user2! = null)
{
User2. UserName = "Shine";
Entities. SaveChanges ();
}

Shortcuts commonly used in VS

1. ctrl+f Find Current file

2, ctrl+shift+f find the entire solution

3. F9 Breakpoint

4, F10 Single Step

5, F11 Single Step Into

6, ctrl+-back to the previous step to see the file

7, SHIFT+F9 fast Monitoring

8, Shift+ctrl+b debugging

Tips

1. Code specification: General return can only be placed at the beginning or end of the program, or there is return in the middle of not know where to exit from

2. Generally go to the database when the data is taken out directly tolist

Open line number in 3.VS tool options

4.VS debugging when there is an error general steps: View Detail->innerexception expand to the innermost of the innerexception view can be, the specific figure is as follows

5. When the conversion is generally selected Int.tryparse this can avoid error

string s = String. Empty

int v1;

if (int. TryParse (S,out v1))

{

  

}

6. When loop traversal, foreach is used to not modify the value of the case, if you need to modify the values of traversed objects choose for traversal

Quick review of C # Basics (tips for programming) to be perfected

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.