C#中的方法签名是什么 [英] What is a method signature in C#

查看:127
本文介绍了C#中的方法签名是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解什么是方法签名及其组成部分。

1.在方法签名中使用public是什么。

2.what是在方法签名中使用bool。

3.在方法签名中使用静态是什么。

4.方法的用法是什么。



我尝试了什么:



i想了解

。在方法签名中使用bool是什么。

3.在方法签名中使用静态是什么。

4.是什么使用方法包含。

解决方案

方法签名是对外界的方法的完整描述:它的名称和参数,但不是它的返回类型。它用于分离两个相似(或重载)的方法,以便系统可以正确。

例如:

  int  MyMethod( int  i){...} 
int MyMethod( double d){...}

有不同的签名,所以如果你用一个整数值调用MyMethod :

  int  res = MyMethod( 666 ); 

您将执行第一个,但

  int  res = MyMethod( 666  0 ); 

将拨打第二个。



public 关键字允许从任何可以访问包含Assembly的代码中调用该方法:公开(C#参考)| Microsoft Docs [ ^ ]



static 关键字表示该方法与任何特定的它是类,但只能通过类名访问,并且不能访问任何与类相关的实例(即非静态)字段,属性,方法或事件: static(C#Reference)| Microsoft Docs [ ^ ]



bool 是一种数据类型,并且要么指示方法的返回类型,或其中一个参数的类型。



方法包含没有意义 - 它不是C#的特定内容,可能需要你做很多解释才能帮忙。


'文档怎么样? ' [ ^ ]?


请参阅:

访问修饰符(C#参考)| Microsoft Docs [ ^ ]

https://www.dotnetperls.com/bool

https://www.dotnetperls.com/static

https://www.dotnetperls.com/contains

i want to understand what is a method signature and the component of it.
1.what is the use of public in a method signature.
2.what is the use of bool in a method signature.
3.what is the use of static in a method signature.
4.what is the use of method contain.

What I have tried:

i want to understand
.what is the use of bool in a method signature.
3.what is the use of static in a method signature.
4.what is the use of method contain.

解决方案

A method signature is the complete description of a method to the outside world: its name, and parameters, but not it's return type. It serves to separate two similar (or overloaded) methods so that the system can all the right one.
For example:

int MyMethod(int i) { ... }
int MyMethod(double d) { ... }

Have different signatures, so if you call MyMethod with an integer value:

int res = MyMethod(666);

You will execute the first one, but

int res = MyMethod(666.0);

will call the second.

The public keyword allows the method to be called from any code which can access it's containing Assembly: public (C# Reference) | Microsoft Docs[^]

The static keyword means that the method is not associated with any particular instance of it's class, but can be accessed only via the class name, and cannot access any class instance related (i.e. non-static) field, properties, methods, or events: static (C# Reference) | Microsoft Docs[^]

bool is a datatype, and either indicates the return type of the method, or the type of one of it's parameters.

"Method contain" is meaningless - it's not anything specific to C# and probably needs a lot of explanation by you before we could help at all.


What about 'The Documentation'[^]?


See:
Access Modifiers (C# Reference) | Microsoft Docs[^]
https://www.dotnetperls.com/bool
https://www.dotnetperls.com/static
https://www.dotnetperls.com/contains


这篇关于C#中的方法签名是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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