. Net Programmer Interviewing C # language (answer Scott Hanselman's Questions)

Source: Internet
Author: User

The past few years have been busy looking for projects, catching up on projects, and not having time to dig into what they have learned at work. Now, while looking for a job in this spare time, just can summarize and continue to tamp their own. Net, C # Basic skills. In 05, Scott Hanselman (a Microsoft Principal program Manager) listed on his blog a list of "a good one." NET programmers should know what the great. NET developers ought to Know (more. NET interview Questions) ". After reading this list seriously yesterday, I found that there were still a lot of questions that I didn't know the answer to, and a lot of questions could only give a vague answer. So the initiation of an idea, not to spend some time to answer these questions one by one, you should be to others will help.

Do as you say. His list is divided into six categories for all questions. In the next few days I started answering a class of questions every day. Start with the C # language article today.

1. list the differences between override and new usage. What is shadowing? (Juxtapose the use of override with new. What is shadowing?)

In a nutshell, the subclass override ignores the parent class's method with the same name as the virtual modifier. However, new for the subclass will be obscured by the parent class using the same name as the virtual modifier. It sounds a little bit abstract, as shown in the following code, it's clear.1 public class Animal
2 {
3 Public virtual string dosomething ()
4 {
5 return "I can Breathe";
4?
7}
8
9 public class Bird:animal
10 {
public override string DoSomething ()
12 {
Return "I can Fly";
14}
15}
16
public class Cat:animal
18 {
Public new string DoSomething ()
20 {
Return "I can run";
22}
23}

1 var animal = new animal ();
2 animal. DoSomething ()//I can breathe
3 var bird = new Bird ();
4 Bird. DoSomething ()//I can Fly
5 var cat = new Cat ();
6 Cat. DoSomething ()//I can run

1 var animal = new animal ();
2 animal. DoSomething ()//I can breathe
3 Animal bird = new Bird ();
4 Bird. DoSomething ()//I can Fly
5 Animal cat = new Cat ();
6 Cat. DoSomething ()//I can breathe

The difference between override and new is now clear in the results of the above operation. When cat is animal, cat. DoSomething () can only be used with functions of the parent class. But bird.  DoSomething () or a function that uses its own override. 2. explain the use of virtual, sealed, override, and abstract(Explain the use of virtual, sealed, override, and abstract.) Virtual: Allows the quilt class to be overridden. Sealed: Not allowed to be inherited. Override: Used in subclasses, overrides functions that are decorated with virtual, abstract, or override in the parent class. Abstract: Can only be inherited and cannot be instantiated. The function itself cannot have implementation code, but it can have attribute 3. explain the importance and usage of each part of Foo.bar, version=2.0.205.0, Culture=neutral, publickeytoken=593777ae2d274679d .(Explain the importance and use of all component of this string:Foo.Bar, version=2.0.205.0, Culture=neutral, Publickeyto KEN=593777AE2D274679D) Foo.Bar:Assembly (assembly), the name of the version: revision number, just like ASP. MCV 1.0, 2.0, 3.0Culture: This Assembly applies to the cultural environment PublicKeyToken: The original author is generated when the assembly is published, to identify whether the assembly has been modified by someone else 4. explain the difference between public, protected, private, internal(Explain the differences between public, protected, private and internal) public: all places can be called protected: themselves and subclasses can use private: only from Own class inside with internal: only the current assembly with protected internal: refers to protected orUsage of internal 5. What are the benefits of using the primary Interop Assembly (PIA)?(What benefit does you get from using a Primary Interop Assembly (PIA)?) I do not understand this problem, the Internet to find a little explanation, also can not understand. Who knows this question?  Please enlighten me. 6. What mechanism does UNite know which method to test?(by what mechanism does NUnit know, what methods to test?) Never thought about this question, referring to the answer on the Internet, is through attributes.  Does anyone else have a more detailed explanation? 7. catch (Exception e) {throw e;} and catch (Exception e) {throw;} The difference (what's the Difference Between:catch (Exception e) {throw e;} and catch (Exception e) {throw;})   The former does not retain the original StackTrace, the latter retains the original stacktrace. 8. What's the difference between typeof (Foo) and Myfoo.gettype ()? typeof (Foo), Foo is a class, executed at compile time, Myfoo.gettype (), Myfoo is class A real column that executes at run time. Follow the example of bird and animal above1 var bird = new Bird ();
2 if (bird. GetType () = = typeof (Animal))
3 {
4//Can not go on here
5}
6
7 if (bird is Animal)
: 9
9//can go in here
Ten Console.WriteLine ("Bird is an Animal");
11}

9. Explain What's happening in the first Constructor:public class c{public C (String a): this () {;}; public C () {;}} How are this construct useful?public a (string a): this () {} calls base constructor public C () {}.  The advantage is that when base constructor C () has logic (e.g. initialize domain), duplicate code can be avoided. 10. what is "this"? Can I use it in the static function? (What is This? Can This is used within a static method?) This refers to the current instance itself and cannot be used in a static function. Because static functions do not require an instance to invoke the

. Net Programmer Interviewing C # language (answer Scott Hanselman's Questions)

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.