gpt4 book ai didi

c# - 在任何命名空间之外定义 C# 类

转载 作者:太空狗 更新时间:2023-10-29 22:57:42 25 4
gpt4 key购买 nike

是否可以在任何命名空间之外定义一个(不是接口(interface))?

最佳答案

运行测试,是的,你可以。这是我基于控制台应用程序构建的代码:

using System;
using System.Text;

namespace With_Console_App
{
class Program
{
static void Main(string[] args)
{

Console.WriteLine("This will output something: ");
Console.ReadLine();
some.Print();
Console.ReadLine();
}
}
}

class some
{
public static void Print()
{
Console.WriteLine("something");
}
}

是的,您可以在命名空间之外定义一个类。根据 juharr,它最终位于默认的全局命名空间中。

关于c# - 在任何命名空间之外定义 C# 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36460263/

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