Class:
Default:传值
Ref:传址
Out:传出变量值,在c#中传入函数中的变量值必须对其初始化,而通过使用Out关键字就可以不用对变量进行初始化,而在函数中对其进行赋值。采用引用传递。
Method overloading
在类的内部可以使用函数重载,可以通过使用不同类型的参数或者不同个数的参数进行重载方法的定义,如:
不同类型参数
class ResultDisplayer
{
void DisplayResult(string result)
{
// implementation
}
void DisplayResult(int result)
{
// implementation
}
}
不同个数的参数
class MyClass
{
int DoSomething(int x) // want 2nd parameter with default value 10
{
DoSomething(x, 10);
}
int DoSomething(int x, int y)
{
// implementation
}
}
Properties:
Access modifiers for properties:c#可以实现对属性的set或者get访问权限的限制,如:
public string Name
{
get
{
return _name;
}
private set
{
_name = value;
}
}
Constructors:
对于一般的构造函数可以支持重载
Static constructors:
静态构造器没有参数,它只被执行一次,并且是在其他构造器执行之前被执行,它主要用来实现从外部读取信息。
如:
public class UserPreferences
{
public static readonly Color BackColor;
static UserPreferences()
{
DateTime now = DateTime.Now;
if (now.DayOfWeek == DayOfWeek.Saturday
|| now.DayOfWeek == DayOfWeek.Sunday)
BackColor = Color.Green;
else
BackColor = Color.Red;
}
private UserPreferences()
{
}
}
}
注意:这里用到了Readonly关键字,readonly主要是用来完成对变量在运行过程中进行赋值,而且改变量一旦赋值之后,就不能再被改变。