C # Object-Oriented programming
what is Object-oriented ?
Object-oriented programming is a new programming idea proposed by the last 60 's after the structure-oriented programming.
Encapsulation, inheritance, polymorphism
Encapsulation, inheritance, polymorphism is the core of object-oriented programming:
Encapsulation is the first step in implementing object-oriented programming, in which a collection of data or functions is set in a unit (what we call a Class). Encapsulated objects are often referred to as abstract data types
The meaning is: protect the data is not destroyed (for example a TV we can use it but can not arbitrarily change the internal circuit)
Keyword: private,public,protected,internal
public string name;
Inheritance : The main implementation of the inheritance code reuse, save development time in the inheritance of the constructor run order from top to bottom and the destructor is the following, the inheritance statement is as follows:
public class Name: class name
--------------------------------------------------------------------------------------------------------------- -----
When learning polymorphism, you have to mention the virtual method
Virtual method: The method of declaring virtual is a virtual method that defines a virtual method in a base class that can be overridden in a subclass using override
And the process of using rewriting is polymorphic
Virtual public void show ()//define virtual methods
Override public void show ()//rewrite of the method
Base Key Words
Base Keyword:the base keyword is used to access base class members from derived classes The main form is as follows:
Calling a method on a base class that has been overridden by another method
Specifies the base class constructor that should be called when creating an instance of a derived class
(the base keyword cannot be used in a static method)
I wrote here a case of a demonstration
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Inheritance of namespace code
{
Class goods//defines a base class
{
public string Tradecode {get; set;} Define Product number
public string FullName {get; set;} Define the product name
}
Class Jhinfo:goods
{
Define the purchase number
public string Jhid {get; set;}
public void Showinfo ()//Output Stock Number
{
Console.WriteLine ("Arrival number: {0}\n Product code: {1}\n Product name: {2}\n", jhid,tradecode,fullname);
}
}
}
Class Program
{
static void Main (string[] args)
{
Jhinfo JH = new Jhinfo ();//Instantiation of Object
Jh. Tradecode = "Ares 1000";
Jh. FullName = "notebook computer";
Jh. Jhid = "ZS10000";
Jh.showinfo ();
Console.WriteLine ();
Console.readkey ();
}
}
}
C # Object-oriented programming encapsulates inherited polymorphism