Function overload
The same signature with the same function name is wrong, but it is possible to have different signatures for the same functions.
Commissioned
Reference is stored as a type of function. Life uses the delegate keyword, specifying the signature of a function, containing a return type and a list of parameters. After you define a delegate, you can declare a variable of that delegate type. Initializes the variable so that it is used for function references that have the same function signature as the delegate. You can use a delegate variable to call this function. The variable is used as if it were using a function.
With a reference function variable, you can perform an operation that cannot be done otherwise. : The delegate variable is passed as a parameter to a function. The function can then be invoked by the delegate, and you do not need to know which function to run before running it.
Delegate Double processdelegate (double param1,double param2);
Static Double Multiply (double param1,double param2) {return param1*param2;}
Static Double Divide (double param1,double param2) {return param1/param2;}
Main (string[] args)
{
string mainparam1,mainparam2;
processdelegate process;
process=new processdelegate (Multiply};
Console.WriteLine ("{0}", Process (MAINPARAM1,MAINPARAM2));
processdelegate process2=new processdelegate (Divide);
Console.WriteLine ("0", Process1 (MAINPARAM1,MAINPARAM2));
}
You need to give a function name without double quotes instead of a parameter inside a function when you delegate a reference function.
object-oriented Programming OOP
encapsulates the components of some applications as objects. Umluniversal Modeling Language Grammar studies classes and objects. property, field, method
The life cycle of an object: the constructor of the construction phase, allocating the memory space, initializing the parameters of the class. The
destructor, the resource that the object occupies.
Static and instance class objects, static members, static properties, static methods, and no instantiation of objects. The
interface combines implicit public methods and properties to encapsulate a collection of specific features.
Inheritance: Objects in C # can only be derived from a base class. A derived class cannot access a private member of a base class. However, both derived classes and external code can access public members. Derived classes can access protected, and base classes and external code are inaccessible. Also, the base
The
class can be defined as an abstract class, so it cannot be instantiated and needs to be done by inheriting classes.
Polymorphism:
The result of inheritance is that classes that derive from the base class have a certain overlap above the methods and properties. The base class Animal has a method Eatfood () that is invoked from the derived class cow and chicken
Animal cow=new Animal ();
Animal chicken=new Animal ();
Cow. Eatfood ();
Chicken.eatfodd (); The
assigns a variable of a base type to a variable of its derived type.
Animal Myanimal=mycow;
A variable of the base type is converted to a variable of a derived class, and the method of the derived class is invoked.
Cow mycow= (Cow) myanimal;
Mycow. Moo (); The
System.Object is the root of the inheritance hierarchy. All objects can be considered as an instance of class object.
Interface polymorphism:
to establish a variable of the interface type that can be used on objects that support the interface to access the methods and properties provided by the interface. The
does not use the method Eatfood () of the base class to place the method inside the interface, because the interface does not provide the execution code, the derived class Cow, and so on, but provides the execution code for the method inside the interface:
Cow mycow=new Cow ();
Chicken Mychicken=new chicken ();
Iconsume Consumeinterface;
Consumeinterface=mycow;
Consumeinterface. Eatfood ();
Consumeinterface=mychicken;
Consumeinterface. Eatfood ();
contains relationships between objects, set relationships, animal[] animals=new animal[5];
Class myclass{};
internal class myclass{};
public class myclass{};
Public Abstract myclass{};
Public Seales myclass{}; The
stipulates that derived classes cannot be more accessible than inherited base classes:
public class mypubclass{};
Internal class myinterclass:mypubclass{};
when a derived class inherits, if a base class is to be written in front of the interface.
public class myclass:mybase,interface1,interface2{}
None internal can access
Public can access anywhere in the project
abstract Or Internal abstract can only be accessed within the current project, cannot be instantiated, can inherit only
sealed Or internal sealed can only be accessed in the current project, cannot be derived, can only be instantiated
public sealed can be accessed on any project, Cannot derive, can only instantiate
Namespace Swk
{
Public abstract class mybase{}//
Internal class myclass:mybase{}//Inner classes
Public interface imybaseinterface{}//Common interface
Internal interface imybaseinterface2{}//Internal interface
Internal interface imyinterface:imybaseinterface,imybaseinterface2{}//Internal interface inherits public interface and internal interface
Internal Sealed class mycomplexclass:myclass,imyinterface{}
Class Class1
{
static void Main (string[] args)
{
Mycomplexclass myobj=new Mycomplexclass ();
Console.WriteLine (myobj. ToString ());
}
}
}
class MyClass
{
public MyClass () {};//constructor
Public ~myclass () {};//destructor
}
The queue of the constructor
Class MyBaseClass
{
Public MyBaseClass () {}
public MyBaseClass (int i) {}
}
Class Myclass:mybaseclass
{
public MyClass () {}
public MyClass () {int i}
public MyClass () {int I,int J}
}
MyClass myobj=new MyClass ();
To construct a queue:
System.object.Object ();
Mybaseclass.mybaseclass ();
Myclass.myclass ();
MyClass myobj=new MyClass (4);
To construct a queue:
System.Object (). Object ();
Mybaseclass.mybaseclass (int i);
Myclass.myclass (int i);
MyClass myobj=new myclass*3,5);
To construct a queue:
System.Object.Object ();
Mybaseclass.mybaseclass ();
Myclass.myclass (int i,int j);
public class MyBase
{
Public MyBase () {}
Public MyBase () {int i}
}
public class Myclass:mybase
[
Public MyClass (): Base (i);
public MyClass (int i);
public MyClass (int i,int j);
}
MyClass myobj=new MyClass ();
To construct a pair of columns:
System.Object.Object ();
mybase.mybase (int i);
Myclass.myclass ();
public class MyBase
{
Public MyBase () {};
Public MyBase (int i) {};
}
public class Myclass:mybase
{
Public MyClass (): This (5,6) {}
public MyClass (int i) {};
public MyClass (int I,int j) {}
}
MyClass myobj=new MyClass ();
To construct a queue:
System.Object.Object ();
Mybase.mybase ();
Myclass.myclass (5,6);
Myclass.myclass ();
A derived class can inherit from only one base class, only directly from an abstract class, and multiple abstract classes through an inheritance chain.
A class can have more than one interface.
Abstract classes can have abstract members (no code body, must be executed in a derived class, or the derived class itself must be abstract) and non-abstract members (they own the code body, can be virtual, and can be overridden in a derived class).
Interface members must all be executed on a class that uses an interface, and they do not have a body of code. Interface members are defined as public and tend to be used externally. Members of an abstract class can be private, protected, internal, or protected internal members (in which protected internal members can only be accessed in the application's code or derived classes), and the interface cannot contain fields, constructors, destructors, static members, or constants.
Namespace
{
public class Myclass{public int myclassint;}
struct mystruct{public int mystruct;}
class Class1
{
static void Main (string[] args)
{
MyClass mc1=new MyClass ();
MyClass MC2=MC1;
mc1.myclassint=10;
mc2.myclassint=20;
MyStruct mys1=new mystruct ();
MyStruct mys2=mys1;
mys1=10;
mys2=20;
}
}
}
myc1=20;
myc2=20;
mys1=10;
mys2=20;
Public approval code can access
Private is accessed by code in the class
Internal code access within a project
The code in the protected class or derived classes can access the
Public ReadOnly publicly read-only readonly description can only give initial value in constructors
Class MyClass
{
public string getString ()
{
Return ' hear is a string ';
}
}
Virtual can override
The abstract method must override the
Override overrides the method of a base class, and when the method is overridden, the keyword must be used
The extern method is defined elsewhere
public class MyClass
{
Public virtual dosomething ()
{
Base implementation
}
}
public class Mysecondclass:myclass
{
public override DoSomething ()
{
Secondclass Implenmentation,overrides Base Implementation
}
}
You can use the Sealed keyword to show that methods cannot be further modified in a derived class
public class Mysecondclass:myclass
{
Public Sealed dosomething ()
{
Secondclass Implenmentation,overrides Base Implementation
}
}
For the definition of a property: Get Set
public class MyClass
{
private int Myint;
public int Myintpop
{
Get{return Myint;}
Set{if (value<10&&value>3) myint=value;else throw (New ArgumentOutOfRangeException ("MyintPop", Value, " Myintpop value to be between 0~10 ")");}
}
}
Using System;
A summary description of the
namespace Try
{
///<summary>
///myClass.
///</summary>
public class myclass//customizes a class that can be used by any code
{
Public ReadOnly string name;//can only initialize
private int valint;//Private integer functions within constructors, private fields
public MyClass (string NewName)//Custom constructor, initializes the public field
{
name=newname;
//
//TODO: Add constructor logic here
//
}
Public myClass (): This (" DefaultName ")//constructor, using the custom constructor
{
Before the integer default constructor
}
public int valintpop//Common Properties
{
Get
{
Return valint;//Read Properties
}
Set
{
if (value>=0&value<=10) {valint=value;} setting properties, exceeding range output exception
Else{throw (New ArgumentOutOfRangeException ("Myvalint", value, "Valintpop defined between 10~0"));}
}
}
The public override string ToString ()//rewrites ToString ()
{
Return "value:" +valint+ "Name:" +name;
}
}
}