. NET technical interview, written questions summary (13~19)

Source: Internet
Author: User

13. Requirements for objects that can be accessed with foreach traversal

14. What is GC? Why do you have a GC?

15. What is the difference between a value type and a reference type?

16. What are the similarities and differences between interfaces and classes in C #?

17. What is the difference between abstract class and interface (interface)?

18. Is it possible to inherit the Srtring class?

19, the following program operation results:

static void Main (string[] args)

{

Console.WriteLine (Getit ());

Console.readkey ();

}

static int Getit ()

{

int i = 8;

Try

{

i++;

Console.WriteLine ("A");

Return i;//set the returned value to I, and then return as soon as possible (nothing will go back)

}

Finally

{

Console.WriteLine ("B");

i++;

}

}

13, the need to implement the IEnumerable interface or the type of GetEnumerator method

14. GC is a garbage collector (garbage Collection). Programmers don't have to worry about memory management, because garbage collection is automatically managed. The GC can only handle the release of managed memory resources, and for unmanaged resources it cannot be recycled using GC and must be manually recycled by programmers, FileStream and SqlConnection require programmers to call Dispose for resource reclamation. To request garbage collection, you can call Gc.collect (). An object can be recycled when it doesn't have any point, but it doesn't have to be recycled immediately.

15, 1) When assigning a value type variable to another value type variable, the contained value is copied. The assignment of a reference type variable copies only references to the object, not the object itself.

2) A value type cannot derive a new type: All value types are implicitly derived from System.ValueType. But as with reference types, structs can also implement interfaces.

3) value types may not contain null values, however, the nullable type feature allows NULL to be assigned to a value type.

4) Each value type has an implicit default constructor to initialize the default value of that type.

16, different points: can not directly instantiate interface, interface does not include the implementation of the method, the interface can achieve multiple inheritance, the class can only single inheritance, class definition can be split between different source files

The same point: interfaces, classes, and structs can inherit from multiple interfaces, which are similar to abstract base classes: Any non-abstract type that inherits an interface must implement all members of the interface. Interfaces and classes contain, events, indexers, methods, and properties.

Supplemental Knowledge: Interfaces can only define methods (only defined behavior, cannot define implementations that are fields), because events, indexers, and attributes are essentially methods, so an interface may also define events, indexers, and attributes.

17, the same point: cannot be instantiated, can be inherited through the implementation of its abstract method.

Different points: The interface supports multiple inheritance, and abstract classes cannot implement multiple inheritance;

Interface interfaces can define behavior only: Abstract classes can define behavior and may also provide implementations;

The interface contains only methods (method), Events (event), indexer (index), attribute (proprety) signatures, but cannot define fields and methods that contain implementations;

Abstract classes can define fields, attributes, and methods that contain implementations;

Interfaces can be used for value types and reference types, and abstract classes can only be used for reference types.

18, the string class is sealed class therefore cannot inherit.

19, the operation result is a B 9 program is executed by the main function Console.WriteLine (Getit ()); Jump to Getit () method execution, i++ i=9; Console.WriteLine ("a"); output A, return I, then execute the code in Finally, output B, and finally output 9.

. NET technical interview, written questions summary (13~19)

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.