关于主要方法的概念 [英] opps concept about main method

查看:74
本文介绍了关于主要方法的概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友

我想深入了解公共静态void main(string [] args)".
我们可以将main方法用作私有方法吗?
main方法中public,static,void和string [] args的用途是什么?

请任何人给我答复

在此先感谢

hi friends

i want to know deeply about "Public static void main(string[]args)".
and can we use main method as private or not?
what is purpose of public,static,void and string[]args in main method?

please kindly anybody give me reply

thanks in advance

推荐答案

此方法可以是私有的,强烈建议私有..此方法的声明类型也可以是私有的.此外,所有项目模板都会将此方法生成为静态私有方法.

即使通常不使用访问修饰符"private",但generate声明也是私有的,因为这是默认设置,在省略访问修饰符时使用.

这是原因:其他程序集可以引用任何包含"EXE"的程序集.本质上,EXE和DLL,类库和应用程序之间没有任何根本区别.应用程序的唯一特殊功能是其输入方法.此方法设计为由.NET加载程序(或称为.NET的任何部分,即启动.NET应用程序的那个部分)调用;它并非设计为由引用该应用程序的程序集调用(有时会使用该技术).您可以将Main声明为public,并在某些引用程序集中进行调用,但前提是您明知要违反惯例.

同时,.NET甚至任何应用程序都可以调用任何非公共方法引发反射.因此,对于运行该应用程序,不需要公共声明入口点.

这个问题与OOP无关.

—SA
This method can be private and is strongly recommended to be private. The declaring type of this method also can be private. Also, all the project templates generate this method as static private.

Even though the access modifier "private" is usually not used, the generate declaration is private, because this is the default, used when an access modifier is omitted.

Here is why: any assembly including "EXE" could be referenced by other assemblies. Essentially, there is not any fundamental differences between EXE and DLL, class libraries and applications. The only special feature of application is its entry method. This method is designed to be called by .NET loader (or whatever that part of .NET is called, the one starting the .NET application); it is not designed to be called by an assembly referenced the application (the techniques which is used sometimes). You can declare Main as public and call if from some referencing assembly, but only if you knowingly want to violate the common practice.

At the same time, .NET and even any application can call any non-public method throw Reflection. So, for running the application, the public declaration of entry point is not needed.

This question has nothing to do with OOP.

—SA


它们是静态的,即使不创建其所在类的对象也可以调用它们.(并且只能调用一次)
无效,因为它们不返回任何值.
string [] args-因为字符串中可以包含任何类型的值.(int,decimal,char ..)
main表示程序的起点!
They are static so as to call them even without creating the object of the class they are in.(and also to be called only once)
void since they don''t return any value.
string[] args- since strings can take any kind of values in them.(int,decimal,char..)
main indicates the starting point of the program!


main方法是任何程序的起点,我们不能将main方法声明为私有方法,main方法不会返回任何内容就是为什么我们要写
公共静态void主

[警告!请不要使用此答案,这是不正确的.不要感到困惑.请在下面查看我的评论并正确回答— SA]

main method is the starting point for any program, we can''t declare main method as private, main method won''t return anything that''s why we are writing
public static void main

[WARNING! Please don''t use this answer which is incorrect. Don''t get confused. Please see my comments below and correct answer — SA]


这篇关于关于主要方法的概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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