Inheritance: Resolving code redundancy in a class;
Main function
static void Main (string[] args)
{
Rep R = New Rep ("Zhang San");
R.msg ();
}
Console.readkey ();
Parent class
public class Person
{
private string _name;
public string Name
{
get {return _name;}
set {_name = value;}
}
Public person (string name)
{
This. name = name;
}
}
Subclass, inheriting the Name property inside the parent class
public class Rep:person
{
Public Rep (string name): base (name) {}
public void Msg ()
{
Console.WriteLine ("Hello everyone, my name is {0}.") ", this. Name);
}
}
The This in the constructor: there are several parameters that represent which constructor (the constructor that invokes the current class);
Base: Call the constructor inside the parent class.
Reference namespace: using+ class name; (Calling the class inside the namespace project)
Value types and reference types:
Reference type: string, custom class, Array (three);
Others are value types: int,double,bool,char,enum,struct,decimal (decimal type);
Storage: Values of value types are stored in the stack of memory;
Stack: Allocated memory space during compilation;
The value of a reference type is stored in the heap of memory;
Heap: Dynamically allocated memory space during program run;
Difference:
1. Value types and reference types are not stored in the same place in memory;
2. When passing a value type and passing a reference type, the delivery method is different;
Value types are called value passes; reference types are referred to as reference passes;
The three functions of new:
1. Open up space in memory;
2. Creation of objects in open space;
3. Call the constructor of the object;
Equals: for string type; case-insensitive comparison;
Trim (): Go space before and after
C # Inheritance