C # Primary knowledge point collation and the simple use of VS

Source: Internet
Author: User

C # Preprocessor Directives
#define #undef declares a variable that does not need to be assigned a value
Note that it must be placed on the using above, as

#define TESTusing  system.xxx;  Public class task{    public  Task ()    {    }}

#region #endregion
This is a set of instructions to help manage the layout of your code

#if #else #elif #endif
If else there is nothing to say. But this usually goes with # define.

#warn #error
Output warning or error

#if DEBUG

#endif

This is useful for specifying a block of code that executes only when debugging, and is automatically deleted when it is released.

Of course, these functions can be implemented with a set of shortcut keys: Ctrl + K, CTRL + S

Select a piece of code and use this set of shortcut keys to

Ref parameter

When a parameter is passed to a method, if the parameter is a transferred value, then no matter how it is changed in the method, it will not affect the original value outside the method, but if you add ref, the value will be passed as a reference.

Static void Reset (refint  b) {    1;} Static void Main (string[] args) {    int0;    Reset (ref  n);}

Note that when defining and using methods, the parameters and arguments must be refbefore they are used.

Optional parameters

Sometimes some parameters are optional and have default values. (a bit like overloading)

Static void Reset (int b,int2,int d=3) {    Console.WriteLine ("  n:{0}", b+c+D);} Static void Main (string[] args) {    Reset (1);}

Note, however, that an optional parameter must be placed in the final definition. It's not right down there.

Static void Reset (int2,int d=3,int  b) {    Console.WriteLine ("  n:{0}", b+c+D);}

Called in order to assign values.

Reset (119); // assign a value to B Reset (119,5); // assigning values to B,c Reset (119,5,7); // assigning values to B,c,d

However, if you do not want to assign values in order, or if some parameters do not want to be assigned, you can call the

Reset (A, D:5); // assigning values to B,d

Class

The concept of attributes

 Public class person{    privatestring  name;          Public string Name    {        set        {            = value;        }         Get         {            return  name;}}    }

If you do not add a set accessor, it becomes a read-only property. (There are also write-only attributes)

 Public class person{    privatestring  name;      Public string Name    {        get        {            return  name;}}    }

It's kind of a simple notation.

 Public class person{    publicstring name{set;  Get;}}

However, this auto-implemented property must have two accessors. Otherwise, it will go wrong, as follows

 Public class person{    publicstring name{get;}}

If you want to set read-only, you can do this by changing access permissions:

 Public class person{    publicstring  Name    {        private set  ;         Get ;    }}

Inherited

① calls the parent class in C # to use base, as

 Public class student:person{    publicoverridevoid  showname ()    {          Base. ShowName ();    }}

This is like a super in Java.

② the method for the parent class, if you want to be overwritten in the future, you must explicitly declare the function as virtual, and the subclass overrides the method must also be declared as override. This is because method defaults are virtual methods in C #. This is very different from Java.

③ Abstract class

If a class is abstract, the methods in that class must also be abstract, and conversely, if a method is abstract, the class must also be an abstract class.

This abstract keyword is the same as in Java and is abstract. Note that abstract methods are declared as abstract and cannot be added to virtual.

④ Sealing Class

Declaring a class as sealed means that the class cannot be inherited by another class. The use of this reference class string

⑤ keyword internal

class or attribute methods with internal are only available to programs under the same assembly (namespace), equivalent to defaultunder Java.

More useful shortcut keys in VS2010

    • Locate Search

In the Edit menu, select "Navigate to" (navigate to) or Ctrl + to open the Locate Search window. Enter the query in the Search bar (the feature of the fuzzy query is strong) and VS2010 will list the relevant result information.

Double-click the search results to reach the code location.

    • Call Hierarchy

Right -click on the method, properties, and constructors to view the call hierarchy, which can be used to understand its associated program structure if it is a newly-inherited project.

    • View References

Ctrl + K + R To view methods, properties, references to constructors, code refactoring, and tools to understand the code structure

VS's WCF Test tools

Path to Microsoft Visual Studio Xx.0\common7\ide\wcftestclient.exe

There is also a third-party service Test tool SoapUI usage similar to

Page Error Event Listener

Web page error is inevitable, the background error processing is not prudent, the data format is not comprehensive enough, it is possible to appear. But these things can not be seen by users, even a tactful point of sorry page to fool it.

To solve this problem, we can overwrite the page's OnError event (which will enter the event when the error occurs in the background), and make the appropriate processing to jump to a specific page

protected Override void OnError (EventArgs e) {    Response.Redirect ("sorry.htm");}

C # Primary knowledge point collation and the simple use of VS

Related Article

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.