请问在诸如方法之类的对象或程序设计中的签名是什么 [英] please what is asignature in object orinted programming in such as methods

查看:107
本文介绍了请问在诸如方法之类的对象或程序设计中的签名是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是初学者

请问在诸如方法

hiii everybody,i''m beginner

please what is asignature in object orinted programming in such as methods

推荐答案

这样的对象编程中,什么是签名?您是否真的需要我搜索
Do you really need I search Wikipedia[^] for you?


name of the method, number and type of the parameters构成方法的Signature .

该方法的return type是该方法的not part of the Signature.

对于方法重载,签名应有所不同.参数的顺序和类型很重要,而参数的名称并不重要,因为当方法的重载中参数的名称不同或相同时,它不会有所不同.

例子

The name of the method, number and type of the parameters constitute the Signature of the method.

The return type of the method is not part of the Signature of the method.

For method overloading the signature should be different. The order and type of the parameters is important whereas the name of the parameter is not significant in the sense that when the names of the parameter is different or same in different overloads of a method it does not make difference.

examples

private void method(string param1, int param2){

}

//Not valid
private int method(string param1, int param2){

}

private void method(string param3){

}
private void method(int param1, string param2){

}


A 签名使方法看起来对于编译器而言是唯一的.

method名称和type 参数的顺序均有助于签名的唯一性.

Methods, constructors, indexers, and operators的特征在于其签名.

签名启用类,结构,接口中成员的overloading 机制.

方法签名由方法的名称类型和种类组成,例如值或引用.
方法签名不包括返回类型,也不包括可能为最后一个参数指定的params修饰符.

构造子签名由类型和种类组成,例如值或引用.构造函数签名不包括可能为最后一个参数指定的params修饰符.

索引器签名属于类型.索引器签名不包含元素类型.

运算符签名由运算符的名称和类型组成..操作员签名不包括结果类型.

签名示例类
A signature makes a method look unique to the compiler.

The method name and the type and order of parameters all contribute to the uniqueness of signatures.

Methods, constructors, indexers, and operators are characterized by their signatures.

Signatures enable the overloading mechanism of members in classes, structs, and interfaces.

A method signature consists of the name of the method and the type and kind, such as value or reference.
A method signature does not include the return type, nor does it include the params modifier that may be specified for the last parameter.

A constructor signature consists of the type and kind, such as value or reference. A constructor signature does not include the params modifier that may be specified for the last parameter.

An indexer signature consists of the type. An indexer signature does not include the element type.

An operator signature consists of the name of the operator and the type. An operator signature does not include the result type.

Signatures Example class
void MyFunc(); // MyFunc ()

            void MyFunc(int x); // MyFunc (int)

            void MyFunc(ref int x); // MyFunc (ref int)

            void MyFunc(out int x); // MyFunc (out int)

            void MyFunc(int x, int y); // MyFunc (int, int)

            int MyFunc(string s); // MyFunc (string)

            int MyFunc(int x); // MyFunc (int)

            void MyFunc(string[] a); // MyFunc (string[])

            void MyFunc(params string[] a); // MyFunc (string[])




ref out 参数修饰符是签名的一部分.

MyFunc(int), MyFunc(ref int), and MyFunc(out int)都是唯一的签名.

返回类型和params修饰符不是签名的一部分,并且不可能仅基于返回类型或基于params修饰符的包含或排除来进行重载.

请注意,包含重复签名的方法(例如MyFunc(int)和MyFunc(string []))存在一些错误,这些签名的多个签名仅在返回类型上有所不同.




The ref and out parameter modifiers are part of a signature.

MyFunc(int), MyFunc(ref int), and MyFunc(out int) are all unique signatures.

The return type and the params modifier are not part of a signature, and it is not possible to overload based solely on return type or on the inclusion or exclusion of the params modifier.

Notice that there are some errors for the methods that contain duplicate signatures like MyFunc(int) and MyFunc(string[]) whose multiple signatures differ only by return type.


这篇关于请问在诸如方法之类的对象或程序设计中的签名是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆