Initial knowledge of C # program Structure
First, write a C # program, comments:
1. Writing Procedures
Static void Main (string[] args)// write code output data { Console.WriteLine (") under the Mian method Hello world! "); // Output "Hello world! " console.readline (); pause }
2. Comments
C # program structure is divided into comments, namespaces, classes, main methods, identifiers and keywords, statements.
Note: line comments start with "//"
Paragraph comments begin with "/*" and End with "*/"
Second, the name space:
C # programs use namespaces for organization, and namespaces can be used either as an internal organizational system for a program or as an organization system that is exposed externally (that is, a way to expose program elements that you own to other programs).
If you want to invoke a class or method in a namespace, you first need to introduce a namespace using a using directive that imports the type members in the namespace into the current compilation unit. The using namespace name.
Using N1; Using A using directive to introduce namespaces N1namespace test02{ class program { static void Main (string[] args) { A oa = new A ();//Example Class A OA in N1 . Myls ();//Call the Myls method in Class A } }}namespace N1// Establish a namespace n1{ Class A //Declare a Class A in the namespace { public void Myls () { Console.WriteLine ("Love You with a Lifetime");//output String console.readline () ; }}
Third, class
A class is a data structure that must be declared before any new class is used, and once a class is declared it can be used as a new type.
[ class modifier ] class[ class name ] [ base class or interface ]
{
[ class Body ]
}
The class name is a representation of the body, it must conform to the naming rules of the identifier, the class generally takes the first letter capitalized noun
namespace N1 // Build namespace N1{ class a // Declare a class a in the namespace { publicvoid myls () { Console.WriteLine (" s"); // Output String console.readline (); }}}
Iv. Main Method
there is only one Main method in a C # program and must be static.
Three of the Main methods can be modified:
Public: shows that the Main method is common, and that the entire method can be called outside the entire class;
Static: The description method is static, that is, the method belongs to the ability of the class, not the specific object of the class. Calling a static method does not make the class's manifested object, it must be called directly using the class name;
Void: This modifier indicates that the method has no return value.
Five, identifiers and keywords:
There are 3 Basic rules for naming the identifiers:
1. Identifiers can only be composed of numbers, letters and underscores;
2. Identifiers must be preceded by letters or underscores;
3. Identifiers cannot be keywords;
VI. C # statements:
Statements are constructs all C # program Prerequisites, can declare local variables, constants, invoke methods, create objects, or assign values to variables, properties, or fields
Console.WriteLine ("Hello world! ");
VII. Naming conventions:
Naming conventions play a very important role in writing code.
1, using the Pascal rule to name the method and type, Pascal's naming rule is that the first letter must be uppercase, and the first letter of the concatenated word is uppercase
Define a public class, and create a public method in the class
Public class Dategrid // Create a common class { publicvoid datebind () // Create a public method { }} in a public class
2. Use the camel rule to name the parameters of the local variable and method, which refers to the first letter of the first word in the name lowercase
Declares a string variable and creates a public method
string sturusername; // declares a string variable sturusername Public void addUser (string strusername,byte[]bypassword); // create a public method with two parameters
3. Prefix "_" before all member variables.
Declare a private member variable in the public class Datebase _connectionstring
class Datebase// Create a public class { privatestring _connectonstring; Declare a private member variable }
4, the name of the interface prefix "I"
Create a public interface iconnectionstring
Interface IConvertible// Create a public interface IConvertible{ byte tobyte (); declares a byte-type method }
5, the name of the method, it is generally named as the verb-bin phrase
Create the Createflie method and the GetPath method in the public file
Public class Flie// Create a common class { publicvoid creatflie (string fliepath) // Create a Creatflie method { } publicvoid getpath (string Path)// Create a GetPath method { }}
6. All member variables are declared at the top of the class and separated by a newline
Declare two private variables _productid and _productname at the top of a class
Public class Product// Create a public class { privatestring _productid; Declare the variable private string _productname at the top of the class ; Declare the variable public void addproduct at the top of the class (string productld, String productName)// Create a public method { }}
7. Naming namespaces with meaningful names, such as company name, product name
Name namespaces with company name and product name
namespace Zivsoft // company name {}namespace ERP// product name {}
8. When using a control, try to name the local variable.
Create a method that declares the string variable title in the method so that it equals the text of the label control
1 Public string GetTitle () // Create a public method 2{3 string title=lbl_ Title.text; // define a local variable 4 return title; // Use this local variable 5 }
Reference page:
Http://www.yuanjiaocheng.net/Linq/linq-tutorials.html
Http://www.yuanjiaocheng.net/Linq/why-linq.html
Http://www.yuanjiaocheng.net/Linq/linq-api.html
Http://www.yuanjiaocheng.net/Linq/linq-query-syntax.html
Http://www.yuanjiaocheng.net/Linq/linq-method-syntax.html
Http://www.yuanjiaocheng.net/Linq/linq-lambda-expression.html
Http://www.yuanjiaocheng.net/Linq/linq-standard-query-operators.html
Http://www.yuanjiaocheng.net/Linq/linq-filtering-operators-where.html
Http://www.yuanjiaocheng.net/Linq/linq-filtering-operators-oftype.html
Http://www.yuanjiaocheng.net/Linq/linq-sorting-operators-orderby-orderbydescending.html
Http://www.yuanjiaocheng.net/Linq/linq-sorting-operators-thenby-thenbydescending.html
C # Initial knowledge