. NET Framework programming (i)----advanced

Source: Internet
Author: User
Tags abstract shallow copy
. NET Framework | programs | Design Q1: Differences between value types and reference types






Q2: Boxing and unboxing of value types

Answer:

Boxing is the conversion of a value type to a reference type. For example, add an instance of a struct in ArrayList.

Steps:

1 allocates memory for reference types from the managed heap. The size of the memory is the size of the value type itself plus additional space including a method table and a Syncblockindex

2 Value-type fields are copied to the memory of the newly allocated object on the managed heap

3 Returns the address of the newly assigned object in the managed heap as a reference to that object.



The unboxing is to get the element of the object on the managed heap to the value type of the stack space.

1 Get the address of the pretend value type on the managed heap

2 Copy from the managed heap to a value type on the stack

Using the DirectCast and CType static methods




The difference between Q3:directcast and CType

CType in transition is stronger than DirectCast. For example: A Int32 value type is boxed as object, DirectCast can only be transformed from object to Int32 (as a unboxing step may be more secure-there is not much transformation), and CType can be transformed from object to Int16 ( Includes unboxing and transition 2 actions)




Q4: Difference between type builder and instance Builder






Q5:memberwiseclone Shallow copy process

Umemberwiseclone creates a new instance of the same type as the current instance, and then copies the non-static fields of the original object. Performs a bitwise copy of the field if the field is of a value type. If the field is a reference type, the reference is copied without copying the referenced object, so that references in the original object and references in the clone point to the same object.

How do I make a deep copy?

Implement the IClonable interface, override the Clone () function of the parent class

Public Function Clone () as Object Implements iclonable

General method: New object to clone, assign the value of a member of the original object to a member of the new object, and return a reference to the new object.

A better approach is to serialize the object into a System.IO.MemoryStream and then deserialize the memory stream immediately to get a new object.




The difference between Q6:module and class

The module is actually a special class. The protection level of the class is friend, which does not contain any instance constructors, and prevents the creation of instances of the class, both methods and variables declared as shared.

Use module is used to implement the access of module external code to members in the module. Secondly, for the convenience of the early VB code transplant.




Q7:vb. The parameter passing in net

There are two kinds of passing ByVal by value, one being passing byref by reference. When passed by value, a copy of the original parameter is copied, and the reference is equivalent to an alias.




The difference between q8:structure and class

1 structs are value types whose instances are allocated on top of the stack, and instances of classes are allocated on the heap, and their references are on stack space.

2 structs cannot be inherited, classes can be inherited.

The default member of the 3 structure is public and its members are not protected, cannot specify an initial value for the variable declaration, cannot define the default copy constructor and array initial size; the variables and constants of the class are private, and the other members are public

The 4 structure never terminates, and the Finalize method is not invoked;

The difference between creating an instance of class and creating a structure instance

Structs are value types whose instances are allocated on top of the stack, and instances of classes are allocated on the heap, and their references are on stack space.




Q9: How to ensure that only one instance of a program in the system is running

1 first get the process of the current program in the system

2 with the name of the process as an argument, all existing processes that are equal to the process name from the system are placed in a process array.

3 loops The process array if there is the execution file name of the process and the file name that currently produces the process. If there is, then the project has been run, exit can be, if not, continue to execute.






Q: The difference between rewriting overrides and overloaded overload

Overloads is an overload of the same class with different parameters for a function of the same name

Overrides is an override of a function in the inheriting class that is marked as overridable in the parent class, implementing functions unique to the inherited class

Q:shadows's role?

When a method in an inheriting class is declared as shadows, all functions in the parent class that have the same name as the method are masked and not inherited in the subclass






Q: The difference between an abstract class (Mustinherit-mustoverride) and an interface

An abstract class cannot be instantiated and can only be implemented by his inheriting class, and interfaces cannot be instantiated and can only be implements.

Abstract classes do not differ from normal classes except that they are mustoverride decorated; the members of an interface can only have nested types, methods, properties, and events.




Q:equals






The difference between q:string and StringBuilder

This distinction is somewhat like the difference between string and StringBuffer in Java.




Q: Simulate a ComboBox interface?






Q: Standard event handlers

System instantiation a reflective student, let him go shopping malls, this time he may encounter many people, when he saw mm, he will bleed.

Module Module1

Class cstudent

Public Event SEEINGMM

Sub Shopping

RaiseEvent SEEINGMM ()

End Sub

End Class



Sub stu_seeingmm () Handles Stu. SEEINGMM ' We define this student to see mm this event occurred

' When he's bleeding.

Console.WriteLine ("Stream Bi")

End Sub



WithEvents Stu as New cstudent ' 1 system instantiate a student with ability to reflect



Sub Main ()

Stu.shopping () ' 2 let him go shopping,

End Sub

End Module




Q: The difference between an abstract class (Mustinherit-mustoverride) and an interface






Q: The difference between an abstract class (Mustinherit-mustoverride) and an interface





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.