Organize knowledge in small and small ways

Source: Internet
Author: User

Organize knowledge in small and small ways

1. virtual override in C #

class A{      public A() {}      public void print1() { Console.WriteLine("print1"); }             public virtual void print2() { Console.WriteLine("print2"); }}   class AA: A{      public AA() {}      public void print1() { Console.WriteLine("print1a"); }      public override void print2() { Console.WriteLine("print2a"); }}   class Program{    static void Main(string[] args)    {        A test = new AA();        test.print1();        test.print2();    } }  

The output is:

print1print2a

The virtual modifier is a virtual method, which implies that its subclass should have its own implementation.

The override modifier is an override method, which overwrites the implementation of the original methods of the base class.

 

2. Sort the pointer and reference again.

(1) pointer: the pointer is a variable, which stores an address and points to a memory storage unit. The reference is essentially the same thing as the original variable, it is just an alias of the original variable.

(2) A const pointer can be provided, but no const reference is provided;

(3) the pointer can have multiple levels, but the reference can only be a level 1 (int ** p is valid while int & a is invalid)

(4) the pointer value can be NULL, but the referenced value cannot be NULL, and the reference must be initialized during definition;

(5) the pointer value can be changed after initialization, that is, it points to other storage units, and the reference will not change after initialization.

(6) "sizeof reference" gets the size of the variable (object) pointed to, while "sizeof Pointer" gets the size of the pointer;

(7) pointer and reference auto-increment (++) operations have different meanings;

(Thanks http://www.cnblogs.com/dolphin0520/archive/2011/04/03/2004869.html)

 

3. binning and unpacking in C #

(1) C # all types in the language are composed of the base class System. object Inheritance, including the most common basic types: int, byte, short, bool, etc., that is, all things are objects.

(2 ).. NET divides data types into value and reference types, the value types defined in C # include Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Char, Float, Double, Bool, and Decimal), enumeration (enum), structure (struct), reference types include: Class, array, interface, Delegate, String, etc.

(3) The value type is to allocate memory in the stack and initialize it at the same time as the Declaration to ensure that the data is not NULL;
The reference type is to allocate memory in the heap, and the initialization is null. The reference type requires garbage collection to recycle the memory.

(4) Packing means to implicitly convert a value type to a reference type object. unpacking means to convert a reference type object (boxed) to any value type.

 

1 int i=0;2 System.Object obj=i;3 int j=(int)obj;

This Code contains the first two sentences and the third sentence for unboxing.

 

1 int i=0;2 System.Object obj=i;3 Console.WriteLine(i+","+(int)obj);

In this Code, the first two sentences are packed, I is converted to string for packing, (int) obj is split once, and the split int value is then packed into string.

(Thanks http://www.cnblogs.com/xiaoshi/archive/2008/05/28/1208902.html)

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.