c# - 不同命名空间中的部分类

标签 c# .net class namespaces partial

我可以在不同的命名空间中创建分部类吗?它会正常工作吗? 例如:

class1.cs

namespace name1
{
    public partial class Foo
    {
        Bar1(){
            return 10;
        }
    }
}

class2.cs

namespace name1.name2
{
    public partial class Foo
    {
        Bar2(){
            return 100;
        }
    }
}

主.cs

using name1;
using name1.name2;

namespace mainClass
{
    public class mainClass
    {
        Foo classFoo = new Foo();
        int Count = classFoo.Bar1() + classFoo.Bar2();
        // Will Count = 110?
    }
}

我应该怎么做才能让它发挥作用? (如果我的例子不正确)

最佳答案

一个类的名称包括它的命名空间,所以 name1.Fooname1.name2.Foo 是两个完全不同的类型。因此,对您的问题的简短回答是:否。

为什么你需要做这样的事情?

关于c# - 不同命名空间中的部分类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4504288/

相关文章:

.net - 反转 ListBox 项目(按 "nothing"降序排序)

.NET Framework 4 ILASM 目标框架 2

r - R中整数类和数字类有什么区别

java - main 中创建的对象不会在其他类中执行

c# - 如何更改内部颜色而不是边框

c# - 如何通过 XAML 在 WPF 中将小写字母转换为大写字母?

c# - 设置变量时堆栈溢出

C# 识别 for 循环中的项目

c# - 填充 ComboBox DataColumn 项和值

php - 从不同的 "method of a class"调用递归 "method of the same class"