C # Learning Basic Concepts 25 Q 1th/4 page _c# Tutorials

Source: Internet
Author: User
Tags modifier readline
Note: This part of the information from the network, if there is infringement, please contact me, I will be the first time to declare a reference or delete it!
When I learned C #, I was looking for someone to ask the data type and the branch statement to start the project. These two days and a comprehensive look at the relevant basic knowledge (learn and Shizhi), summed up 25 questions:
1. What is the difference between a static member and a Non-static member?
2.const and static readonly difference?
What do you mean, 3.extern?
What do you mean, 4.abstract?
What does the 5.internal modifier do?
What does the 6.sealed modifier do?
What is the difference between 7.override and overload?
8. What is an index indicator?
What does a 9.new modifier do?
What does the 10.this keyword mean?
11. Can I use abstract functions to override virtual functions in a base class?
12. Can the sealed class have virtual functions?
13. What is a property accessor?
Can 14.abstract be used with virtual? Can I use it with override?
15. What members can the interface contain?
16. What is the difference between class and structure?
17. What are the problems associated with multiple inheritance of interfaces?
18. What is the difference between an abstract class and an interface?
19. What is the alias indicator?
20. How to manually release resources?
What is 21.p/invoke?
What is the difference between 22.StringBuilder and String?
What is the meaning of 23.explicit and implicit?
What's the use of 24.params?
25. What is reflection?
Here is a reference to my answer (C # language category), if there are inaccurate, not comprehensive, welcome friends to correct me!
1. What is the difference between a static member and a Non-static member?
For:
Static variables are declared with the static modifier, created when the class is instantiated, and accessed through the class
Variables not declared with the static modifier are called non-static variables, created when an object is instantiated, accessed through an object
The same static variable for all instances of a class is the same value, and the same non-static variable of different instances of the same class can be a different value
Non-static members cannot be used in the implementation of static functions, such as non-static variables, non-static functions, etc.
Copy Code code as follows:

Example:
Using System;
Using System.Collections.Generic;
Using System.Text;
Namespace Example01
{
Class Program
{
Class Class1
{
public static String staticstr = "Class";
Public String notstaticstr = "OBJ";
}
static void Main (string[] args)
{
A static variable is accessed through a class, and the same static variable for all instances of the class is the same value
Console.WriteLine ("Class1 ' s Staticstr: {0}", CLASS1.STATICSTR);
Class1 tmpObj1 = new Class1 ();
Tmpobj1.notstaticstr = "TmpObj1";
Class1 tmpObj2 = new Class1 ();
Tmpobj2.notstaticstr = "TmpObj2";
Non-static variables are accessed through objects, and the same non-static variable of different objects can have different values
Console.WriteLine ("TmpObj1 ' s Notstaticstr: {0}", TMPOBJ1.NOTSTATICSTR);
Console.WriteLine ("TmpObj2 ' s Notstaticstr: {0}", TMPOBJ2.NOTSTATICSTR);
Console.ReadLine ();
}
}
}

Results:
Class1 ' s Staticstr:class
TmpObj1 ' s notstaticstr:tmpobj1
TmpObj2 ' s NOTSTATICSTR:TMPOBJ2
2.const and static readonly difference?
For:
Const
Members declared with the const modifier are called constants, initialized at compile time and embedded in the client program
Static readonly
A member declared with the static readonly modifier is still a variable, but has a similar usage to a constant: it cannot be modified after the class is accessed and initialized. But unlike constants, this variable is initialized at run time.
Example:
Test class:
Using System;
Using System.Collections.Generic;
Using System.Text;
Namespace Example02lib
{
public class Class1
{
Public Const String Strconst = "Const";
public static readonly String strstaticreadonly = "Staticreadonly";
Public Const String Strconst = "Const Changed";
public static readonly String strstaticreadonly = "Staticreadonly Changed";
}
}
Client code:
Using System;
Using System.Collections.Generic;
Using System.Text;
Using Example02lib;
Namespace Example02
{
Class Program
{
static void Main (string[] args)
{
After modifying the Strconst initial value of Class1 in Example02, only the Example02lib project is compiled
Then go to the explorer and Example02Lib.dll the newly compiled copy of the Example02.exe directory and execute the Example02.exe
Do not debug directly in the IDE because this will recompile the entire solution!!
You can see that the output of strconst has not changed, and the output of strstaticreadonly has changed
Indicates that the const variable was initialized at compile time and embedded in the client program, while the staticreadonly was initialized at runtime
Console.WriteLine ("Strconst: {0}", Class1.strconst);
Console.WriteLine ("Strstaticreadonly: {0}", class1.strstaticreadonly);
Console.ReadLine ();
}
}
}
Results:
Strconst:const
Strstaticreadonly:staticreadonly
Modified Example:
Test class:
Using System;
Using System.Collections.Generic;
Using System.Text;
Namespace Example02lib
{
public class Class1
{
Public Const String Strconst = "Const";
public static readonly String strstaticreadonly = "Staticreadonly";
Public Const String Strconst = "Const Changed";
public static readonly String strstaticreadonly = "Staticreadonly Changed";
}
}
Results
Strconst:const
Strstaticreadonly:staticreadonly Changed
Current 1/4 page 1234 Next read the full text
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.