foreach(object obj in mycollection)
obj在mycollection中循环读取
相当于for();
Console.Write("{0,6}", "sdfssdfaa"+"\n", "sadfa"+"\n", "asdfa"+"\n")
0这位表示输出后面的第几个数
console.writeline("");和c++中的printf("");作用一样
console.read();从标准输入流读取下一个字符。
public abstract class shape
{
public abstract double getarea();
}
public class circle :shape
{
public override double getarea()
{
return system.math.pi*radius*radius;
}
}
一次委托调用多个方法称为多播。
可以通过'+'、'-'来实现多播的增减
委托1、委托2
委托3=委托1+委托2,则委托3,调用的是委托2的方法。
委托3=委托2+委托1.则委托3,调用的是委托1的方法。
委托3=委托3-委托1,则委托3,调用的是委托2的方法。
类名 d3 = d1+d2;等同于
类名 d3 = (类名)delegate.combine(d1,d2);
类名 d3 = (类名)multicastDelegate.combine(d1,d2)
reverse(string_expression)
string_expression 字符串或二进制数据类型的表达式
public class shape
{
protected string color;
public shape(string color)
{
this.color = color;
}
}
public class rectandular:shape
{
protected double length,width;
public circle(string color,double radius)
{
this.color = color;
this.radius = radius;
}
}
public class square:rectandular
{
public square(string color,double side)
{
this.color = color;
this.length = this.width = side;
}
}
两个效果一样
public class square :rectandular
{
public square(string color,double side):base(color,side,side){}
}
[Flags]
public enum NuiInitializeFlags:uint
{
usess = ox01;
usecolor = 0x02;
useskeleton = 0x03;
}
flags标签作用是下面枚举的可以组合使用
system.sort(array)
对数组array进行排序
system.sort(array,array)
system.sort(array,IComparer)
system.sort(array,array,IComparer)
(1)声明事件的委托
public delegate void EventHandler(object sender,EvnentArgs e);
sender表示事件源 e 表示与该事件相关的信息。
(2)声明事件本身
public event EventHandler Printer
声明一个printer事件,类型为EvnentHandler.
注册事件
+=
移除事件
-=
F(object sender,EventArgs e)
public delegate void eventhandler(object sender,eventargs e)
class progrem
{
public event eventhandler print;
public void F(object sender, eventargs e)
{
console.writeline("ss");
}
static void main(string[] argv)
{
progrem p = new progrem();
p.print += new eventhandler(p,F);//添加事件
p,print -= newe eventhandler(p,F);//移除事件
if(p.print != null)
{
p.print(null,null);//调用事件参数都为NULL
}
}
}
public void maxminarray(int []a,out int max,out int min,out double avg)
out 代表该参数是输出型参数
public TextBox()
{
text = "text1";
fontname = "宋体";
fontsize = 12;
multiline =false;
}
public string Text
{
get
{ return text;}//可读属性
set
{return value;}//可写属性
}
委托和c++的函数指针差不多
获取一个函数的入口
与c++指针不同之处委托时面向对象的,是引用类型
委托使用关键字delegate
委托先定义后实例化最后调用
定义
delegate int somedelegate(int nID,string sName);
实例化
somedelegate dl = new somedelegate(wr.InstanceMethod);
最后调用
dl(5,"aaa");
class shape
{
public virtual double area()
{
}
}
class Triangle: shape
{
public override double area()
{
}
}
override 表示继承基类中的虚函数的方法
void Sort(ref int x,ref int Y,ref int z)
ref 代表该参数是引用型参数
class shape
{
public double area();
}
class Triangle:shape
{
new public double area();
}
添加new表示重载基类中的方法