gpt4 book ai didi

c# - 在 C# 中,将方法包含在此类中的目的是什么?

转载 作者:行者123 更新时间:2023-11-30 13:28:11 25 4
gpt4 key购买 nike

我是 C# 新手。将 main() 方法放在“类”中的目的是什么。不会为这个“所谓的”类创建任何对象。我不知道他们为什么将整个程序视为类和方法。还有为什么 main() 函数被称为方法?显然它在类中,但我总是将它称为函数。像这样:

using System;
public class MyApp // What is the purpose of this class?
{
public static void main() // Why is this called a method & not a function when no objects use it?
{
//Statements Here
}
}

最佳答案

在 C# 中,没有纯(裸)函数;所有可执行代码都存在于类的上下文中。类的可执行成员(函数)称为方法。这只是事物在语言中的定义方式。

这是当今面向对象编程的标准;您可能想对其进行更多研究。

关于c# - 在 C# 中,将方法包含在此类中的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6852432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com