c#中的方法是什么意思

大家帮我解释一下!方法和属性,委托,事件!!我现在有点晕!!

哈哈。。。奇怪,方法你都不怎么懂,怎么可能和属性,委托事件之类的混淆呢。。。
我给你解释下,都是个人理解。
method,方法。就是c/c++中的函数,如果你不懂得函数,你就理解成完成某种特定任务的一个代码模块。
property,属性。(这里还有个attribute,也可以翻译成属性,但有些书把attribute翻译成性质,或者干脆两者都不翻译直接用英文。)是c#中独有的一种机制,可以理解成私有成员(字段field)的访问器。
event,事件。事件驱动不知道你听说过没,如果进行人机交互,用户干了什么程序要设法知道和捕捉,那么这个事件就是你干了什么的一个抽象,比如,单击鼠标左键就是一个事件。
deleget,委托。就是c++中的函数指针,只是类型安全的。或者你可以理解成它就是一个方法的别名,而且它可以绑定到不同的方法只要规格一致(即参数类型个数,返回值)
温馨提示:内容为网友见解,仅供参考
第1个回答  2008-04-04
方法和属性 是属于类的成员
就是说类包括属性和方法,

例如,人比作一个类,
人的属性就有:名字,性别,年龄等(变量或是常量),
人的方法就有:吃饭,睡觉,上班等(运算,计算,事情)。

事件可以理解为现实生活中发生的各种事情,

委托就说个例子吧
例如,
第一天,老板找了个秘书并教给秘书怎么做工作,
第二天,老板拿了一堆文件放到秘书办公桌上,对秘书说帮我处理完这写报表,这就形成了一个委托,老板委托秘书帮他完成一份工作, 就是事先写好方法,事后调用。
第2个回答  2015-12-21
1.让方法返回多个参数
1.1在方法体外定义变量保存结果

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Method
{
class Program
{
public static int quotient;
public static int remainder;
public static void Divide(int x, int y)
{
quotient = x / y;
remainder = x % y;
}
static void Main(string[] args)
{
Program.Divide(6,9);
Console.WriteLine(Program.quotient);
Console.WriteLine(Program.remainder);
Console.ReadKey();

}
}
}

1.2使用输出型和输入型参数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Method
{
class Program
{
public static void Divide(int x, int y, out int quotient, out int remainder)
{
quotient = x / y;
remainder = x % y;
}
static void Main(string[] args)
{
int quotient, remainder;
Divide(6,9,out quotient,out remainder);
Console.WriteLine("{0} {1}",quotient,remainder);
Console.ReadKey();
}
}
}

2.方法的重载

方法重载是面向对象对结构化编程特性的一个重要扩充
构成重载的方法具有以下特点:
(1)方法名相同
(2)方法参数列表不同
判断上述第二点的标准有三点,满足任一点均可认定方法参数列表不同:
(1)方法参数数目不同:
(2)方法拥有相同数目的参数,但参数的类型不一样。
(3)方法拥有相同数目的参数和参数类型,但是参数类型出现的先后顺序不一样,
需要注意的是:方法返回值类型不是方法重载的判断条件。
3.方法的隐藏

namespace 方法隐藏
{
class Program
{
static void Main(string[] args)
{
Parent p = new Child();
p.show();
Console.ReadKey();
}
}
class Parent
{
public void show()
{
Console.Write("父类方法");
}
}
class Child : Parent
{
public new void show()
{
Console.Write("子类方法");
}
}
}

namespace 方法隐藏
{
class Program
{
static void Main(string[] args)
{
Parent.show();
Console.ReadKey();
Child.show();//父类方法
}
}
class Parent
{
public static void show()
{
Console.Write("父类方法");
}
}
class Child : Parent
{
public static new void show()
{
Console.Write("子类方法");
}
}
}

在未指明成员存储权限的前提下,其中的成员都是私有的。
namespace 方法隐藏
{
class Program
{
static void Main(string[] args)
{
Parent p1= new Parent();
Parent p2 = new Child();
p1.show();//父类方法
p2.show();//父类方法
((Child)p2).show();//父类方法
Console.ReadKey();
}
}
class Parent
{
public void show()
{
Console.WriteLine("父类方法");
}
}
class Child : Parent
{
new void show()
{
Console.WriteLine("子类方法");
}
}
}

4.方法重写和虚方法的调用
namespace 方法重写
{
class Program
{
static void Main(string[] args)
{
Parent p1 = new Parent();
Parent p2 = new Child();
p1.show();
p2.show();
((Parent)p2).show();//子类方法
Console.ReadKey();
}
}
class Parent
{
public virtual void show()
{
Console.WriteLine("父类方法");
}
}
class Child:Parent
{
public override void show()
{
Console.WriteLine("子类方法");
}
}
}
第3个回答  2008-04-04
方法就是成员函数
第4个回答  2012-03-12
我看过他们的解答懵了
相似回答