gpt4 book ai didi

C# [使用] 作为数据注解

转载 作者:行者123 更新时间:2023-12-04 17:03:07 25 4
gpt4 key购买 nike

我在来自不同类的两种方法之间有一个模棱两可的引用。

这些类位于共享相同结构的不同命名空间中,例如:

MyApp.Models.Folder1.Class1
MyApp.Models.Folder2.Class2

为什么我不能这样使用?
using MyApp.Models;
//and use this static method
Folder1.Class1.StaticMethod();

有什么方法可以将命名空间仅用于方法吗?喜欢:
[using(MyApp.Models.Folder1)]
public ContentResult SomeGetMethod(){
if(Class1.StaticBooleanMethod()) return "nice baby!";
return "that was horrible!";
}

最佳答案

Why I can't use like this?



来自 MSDN documentation , using 指令不会让您访问嵌套在您指定的命名空间中的任何命名空间。

And is there any way to use a namespace just for a method? like:



没有办法做到这一点,但是您可以完全限定名称:
if (MyApp.Models.Folder1.Class1.StaticBooleanMethod()) return "nice baby!";

或者使用别名:
using Folder = MyApp.Models.Folder1;
...
if(Folder.Class1.StaticBooleanMethod()) return "nice baby!";

关于C# [使用] 作为数据注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28400786/

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