gpt4 book ai didi

C# 控制台如何工作?

转载 作者:太空狗 更新时间:2023-10-30 00:19:31 25 4
gpt4 key购买 nike

这是一个非常基本的问题,

但是怎么样,比如

Console.Write("test");

工作?

Console 是一个类,而不是一个对象。

我以控制台为例,因为它很常用,但我见过很多使用 Class.method() 而不是 object.method() 的例子。

最佳答案

该方法称为静态方法:Static Classes and Static Class Members (C# Programming Guide) .

您不需要实例来调用静态类成员:

A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created. Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.

关于C# 控制台如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19409971/

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