簡體   English   中英

如何不將 class 暴露給任何其他 class 而不是一個? (C#)

[英]how to not expose a class to any other class but one? (C#)

我有一個命名空間 ABC,它有一種形式 class、F 和一個普通的 class C。 現在我有了另一個名稱空間 XYZ,其中包含許多不同的類。 現在,F 僅在 C 中使用,在程序中沒有其他地方使用。 其他所有類都使用 C,而不是 F。

在 Visual Studio (2010) 中,從 XYZ 命名空間中的類中,我可以看到智能感知下拉列表中列出的 F(因為我已經引用 ABC 來使用 C)。 我該如何防止呢?我只想要 C 那里。 只要我可以使用來自 XYZ 的 C,任何方法都足夠了。

謝謝。

你能在你的 C class 內部制作一個嵌套的 class 嗎?

public class C
{
    public C()
    { }

    class F : Form
    {
        ...
    }
}

我不確定這是否適用於您的場景,但它可以解決 Intellisense 問題,同時滿足上面列出的要求。

有什么理由不能將它放在另一個命名空間中以對其他類隱藏它,例如命名空間 ABC.Forms?

If it were anything other than a form class (therefore is a partial class if you are using a recent version of .net) - I would say, why not make it an inner class to C - but I doubt that would be neat with a形成 class。

我會 go 更改命名空間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM