. 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, I can sum up and continue to consolidate my. NET and C # basic skills. In, Scott hanselman (a Microsoft principal program manager) listed a list on his blog about "A good. Net ".ProgramWhat great should the clerk 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 The demo is clear.
  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 Or Internal 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
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.