Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#:Can';不包括来自其他命名空间的类_C#_.net_Visual Studio - Fatal编程技术网

C#:Can';不包括来自其他命名空间的类

C#:Can';不包括来自其他命名空间的类,c#,.net,visual-studio,C#,.net,Visual Studio,我有一个奇怪的问题 我创建了两个类AdvertisementHelper(名称空间AdvertisementHelper)和Doof(名称空间blabla),现在我想在类AdvertisementHelper中使用来自类Doof的方法bad_代码 AdvertisementHelper.cs: using blabla; namespace AdvertisementHelper { class AdvertisementHelper { Doof d = new

我有一个奇怪的问题

我创建了两个类AdvertisementHelper(名称空间AdvertisementHelper)和Doof(名称空间blabla),现在我想在类AdvertisementHelper中使用来自类Doof的方法bad_代码

AdvertisementHelper.cs:

using blabla;
namespace AdvertisementHelper
{
    class AdvertisementHelper
    {
        Doof d = new Doof();
        d.bad_code();
    }
}
Doof.cs:

namespace blabla
{
    class Doof
    {
        public void bad_code()
        {
        }
    }
}
这不是我的第一个C#程序,我已经做过很多次了,我从来没有遇到过这样的问题。 blabla和AdvertisementHelper是同一VisualStudio项目的一部分。

d、 在此上下文中未定义错误代码和错误代码

.NET Framework 4.7.2

您不能让代码(即方法调用)在类中的任何位置浮动

class AdvertisementHelper
{
    Doof d = new Doof(); // <= OK, because interpreted as class field
    d.bad_code();        // <= doesn't work!
}
类广告帮助器
{
Doof d=new Doof();//不能让代码(即方法调用)在类中的任何位置浮动

class AdvertisementHelper
{
    Doof d = new Doof(); // <= OK, because interpreted as class field
    d.bad_code();        // <= doesn't work!
}
类广告帮助器
{

Doof d=新的Doof();//Make class Doof public这两个类都是在同一个程序集中定义的,因此它仍应使用默认值
internal
。代码不在方法中…@Fildor good catchMake class Doof public这两个类都是在同一个程序集中定义的,因此它仍应使用默认值
internal
。代码不在方法中od…@Fildor good catchiomg我太傻了哈哈哈:D@Simon2215无论谁告诉你他没有犯那个确切的错误,他都是在欺骗你,或者从5分钟前就开始编码了我已经做了很多年的编程,但没有注意到这个wtf:D谢谢你XDD这是其中的一件事…你看不见它。如果你不看,你可以看它1000次,然后你不喜欢的同事走过你的屏幕…天哪,我太傻了哈哈哈:D@Simon2215不管是谁告诉你他没有制造出那样的雾ake从5分钟前就开始对你撒谎或编码了。(我们都这么做了-至少有一次。)我已经编程多年了,但没有注意到这个wtf:D谢谢你XDD这是其中之一…你看不见它。如果你看不见,你可以看它1000次,然后你不喜欢的同事走过你的屏幕,然后。。。