我在解決方案中有兩個項目 - 一個是庫,另一個是主程序。 庫中某個類的構造函數創建了其他幾個對象。不幸的是,當我在主應用程序中調用該構造函數時,應該是看不見的。有什麼辦法解決這個問題嗎?來自另一個項目的構造函數
的,我說的是什麼例子:
namespace Library
{
public class Foo
{
public Bar bar;
public Foo()
{
Bar bar = new Bar();
}
}
}
namespace Project1
{
class Program
{
static void Main(string[] args)
{
Foo foo = new Foo();
//bar is not accessible here
}
}
}
的創建者可以訪問此項目,因此缺少項目引用的聲音。 – usr
你怎麼使用'Bar'?它只存在於構造函數中。它將在'Foo()'中創建,並且它不會被分配給任何'Foo'的成員,它將消失。 –
我已經添加了參考。 – user3184801