. Net programmers interview C # Language (answer Scott hanselman's question ))

Source: Internet
Author: User
Over the past few years, I have been busy searching for projects and catching up with projects. I don't have time to study what I learned at work. Now, while looking for a job, we can sum up and continue to consolidate our own. NET and C # basic skills. In, Scott hanselman (a Microsoft principal program manager) listed a list on his blog about "a good one. what great should net programmers know. NET developers ought to know (more. net interview questions )". after carefully reading this list yesterday, I found that I still had a lot of questions and did not know the answer at all. Many questions can only provide a vague answer. so I came up with an idea to answer these questions one by one. It should be helpful to others.

 

Just do it. his list divides all problems into six categories. in the next few days, I began to answer a category of questions every day. today we will start with the C # language.

 

1.Listing override is different from using new. What is shadowing?(Juxtapose the use of override with new. What is shadowing ?)

In short, the override of the subclass will ignore the Same Name method of the parent class modified with virtual. however, the new sub-class will be overwritten by the method of the same name modified by the parent class using virtual. it sounds a little abstract. Use the following code to demonstrate it.
 1  public class Animal
2 {
3 public virtual string DoSomething()
4 {
5 return "I can breathe";
6 }
7 }
8
9 public class Bird : Animal
10 {
11 public override string DoSomething()
12 {
13 return "I can fly";
14 }
15 }
16
17 public class Cat : Animal
18 {
19 public new string DoSomething()
20 {
21 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 obvious in the above running results. when Cat is animal, Cat. dosomething () can only use functions of the parent class. but Bird. dosomething () still uses its own override function. 2. Explain virtual, sealed, override and abstract usage(Explain the use of virtual, sealed, override, and abstract .) virtual: Allows quilt class rewriting. sealed: cannot be inherited. override: Used in child classes. It is used to override functions modified with virtual, abstract, or override in the parent class. abstract: it can only be inherited and cannot be instantiated. the function itself cannot have implementation code, but it can have attributes 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 each component of this string: Foo. bar, version = 2.0.205.0, culture = neutral, publickeytoken = 593777ae2d274679d) Foo. bar: Assembly name, version: version number, just like ASP. MCV 1.0, 2.0, 3.0 culture: this Assembly applies to the cultural environment publickeytoken: generated when the original author published this Assembly to identify whether the Assembly has been modified by others. Differences between public, protected, private, and internal(Explain the differences between public, protected, private and internal) Public: protected can be called in all places: You can use private: Only internal in your own class: only protected internal can be used in the current Assembly: Protected OrInternal usage 5. What are the benefits of using primary InterOP assembly (PIA?(What benefit do you get from using a primary InterOP assembly (PIA )?) I don't understand this question at all. I went online to find an explanation and I couldn't understand it. Who knows this question? Please enlighten me. 6. What mechanism does unite use to know which method to test?(By What mechanic does nunit know what methods to test ?) I have never thought about this question. I have referred to the online answer through attributes. Do other people have any more detailed explanations? 7. catch (exception e) {Throw E;} and catch (exception e) {Throw;} (what is the difference between: Catch (exception e) {Throw E ;} and catch (exception e) {Throw;}) the former does not retain the original stacktrace, and the latter retains the original stacktrace. 8. what is the difference between typeof (FOO) and myfoo. getType ()? Typeof (FOO), foo is a class, executed during compilation, myfoo. GetType (), myfoo is a real column of the class, and executed at runtime. The above bird and animal examples are used
 1 var bird = new Bird();
2  if (bird.GetType() == typeof(Animal))
3 {
4 // can not go in here
5  }
6
7  if (bird is Animal)
8 {
9 // can go in here
10   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 is 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. to avoid repeated code. 10. What is "this? Can it be used in static functions?(What is This? Can this be used within a static method ?) This refers to the current instance and cannot be used in static functions. Because static functions do not need instances to call
The personal blog of Lipu Li Pu was published by the author under the 2.5 mainland China license agreement. you are welcome to repost, interpret, or use it for commercial purposes, but you must keep the signature Li Pu (including the link) in this article. If you have any questions or negotiate with the Authority, please leave a message for me

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.