Use the C # reflection design to support scalable plug-ins,
1. Design Interface Class:
public interface IBase{ void Somefun();}
2. Design extension plug-ins:
class PluginCls:IBase{ public void Somefun() { Console.WriteLine("hello ,i am derived class"); }}
3. Main Program Design:
Class Program {static void Main (string [] args) {Assembly asm = Assembly. loadFile (@".... \ PluginCls. dll "); Type [] clsTypes = asm. getTypes (); // you can access all types defined in the Assembly. // Type [] clsTypes = asm. getExportedTypes (); // This method can only access the public-defined Type foreach (Type e in clsTypes) {if (e. isClass & typeof (IBase ). isAssignableFrom (e) // compatible with {IBase mth = (IBase) Activator. createInstance (e); // class instance to construct mth. somefun (); // call the implementation method of the plug-in class} Console. readKey ();}}
Program output:
In this way, the main application can load plug-ins designed by other people, without worrying about the new types defined by the plug-in, as long as the plug-in is designed according to the given interface principles,
The main program can be seamlessly loaded.
Reference: CLR via C #, Chapter 2
Jeffrey's implementation is too embarrassing. The book is a classic book, and his book is recommended for the split of walls!
Use the maximum number of n numbers in C Language
# Define n 20
Main (){
Int a [n] = {...};/* Data defined in advance or input */
Int I, max;
Max = 0;
For (I = 0; I <n; I ++ ){
If (a [I]> max) max = a [I];
}
Printf ("The max number is % d \ n", a [I]);
}
C Language
The first question is not clear.
Question 2:
# Include "stdio. h"
Void main ()
{
Int t, n;
Printf ("Please input a number: \ n ");
Scanf ("% d", & n );
While (n)
{
T = n % 10; // calculate the remainder to obtain the last digit.
Printf ("% d", t );
N = n/10; // remove the last digit except 10.
}
}
Question 3:
# Include "stdio. h"
Void main ()
{
Int I;
For (I = 1; I <= 100; I ++)
{
If (I % 5 = 0)
Continue;
Printf ("% d \ t", I );
}
}