错误:类型名称“实例”不存在 [英] Error: the type name "instance" does not exist
问题描述
我想我的代码中出现了幻影问题。我在类库项目中有一个名为 RedCupSkinManager 的类。我为这堂课创造了一个公共场合。但是,在我的主Windows应用程序项目中,我无法访问该实例。
在我的RedCupSkinManager类中:
namespace RedCupSkin
{
public class RedCupSkinManager
{
private static RedCupSkinManager实例;
public static RedCupSkinManager实例
{
< span class =code-keyword> get { return 实例? (instance = new RedCupSkinManager()); }
}
}
}
在我的主要应用程序中:
使用 RedCupSkin;
使用 RedCupSkin.Controls;
命名空间 RedCup
{
public partial class RedCup:RedCupForm
{
private readonly RedCupSkinManager redcupSkinManager;
public RedCup()
{
InitializeComponent();
redcupSkinManager = new RedCupSkinManager.Instance;
}
}
}
在vs-2015或作为我有任何建筑问题class是不是静态的,因此不调用静态函数抛出这个类?
提前致谢。
我尝试过:
我在VS-2015开发。我有Build RedCupSkin作为它的类库,我在我的RedCup Windows应用程序中添加了引用(RedCupSkin.dll)。
但是,我得到例外类型名称实例不存在。
试试这个:namespace RedCupSkin
{
public class RedCupSkinManager
{
// 私人'ctor for Singleton
private RedCupSkinManager()
{
}
private static RedCupSkinManager _instance;
public static RedCupSkinManager实例
{
< span class =code-keyword> private set {_instance = value ; }
get
{
if (_ instance == null )_ instance = new RedCupSkinManager();
return _instance;
}
}
}
}在表格中:
私人 RedCupSkinManager redcupSkinManager;
private void YourForm_Load( object sender,EventArgs e)
{
redcupSkinManager = RedCupSkinManager.Instance;
}我假设你的目标是让'RedCupSkinManager成为单身,就像这里显示的简单示例一样;从相对简单到复杂,有很多方法可以做到这一点。请参阅Jon Skeet的综合评论:[ ^ ]。
你不需要新
redcupSkinManager = RedCupSkinManager.Instance;
Hi,
I think I am getting ghosted problem in my code. I have a Class named RedCupSkinManager in Class Library projects. I have created a public instant for this class. But, in my Main Windows Application project I could't access the instance.
In my RedCupSkinManager class:
namespace RedCupSkin
{
public class RedCupSkinManager
{
private static RedCupSkinManager instance;
public static RedCupSkinManager Instance
{
get { return instance ?? (instance = new RedCupSkinManager()); }
}
}
}
In my Main Application:
using RedCupSkin;
using RedCupSkin.Controls;
namespace RedCup
{
public partial class RedCup : RedCupForm
{
private readonly RedCupSkinManager redcupSkinManager;
public RedCup()
{
InitializeComponent();
redcupSkinManager = new RedCupSkinManager.Instance;
}
}
}
Is there any building problem in vs-2015 or as my class is not static thus while not calling static function throw this class?
Thanks in advance.
What I have tried:
I am developing in VS-2015. I have Build RedCupSkin as its a class library and I have added the reference(RedCupSkin.dll) in my RedCup Windows application.
But, I am getting exception "the type name "instance" does not exist".
Try this:namespace RedCupSkin { public class RedCupSkinManager { // private 'ctor for Singleton private RedCupSkinManager() { } private static RedCupSkinManager _instance; public static RedCupSkinManager Instance { private set { _instance = value; } get { if(_instance == null) _instance = new RedCupSkinManager(); return _instance; } } } }In the Form:
private RedCupSkinManager redcupSkinManager; private void YourForm_Load(object sender, EventArgs e) { redcupSkinManager = RedCupSkinManager.Instance; }I assume your goal here is to make the 'RedCupSkinManager a "singleton," as in the simple example shown here; there are a number of ways to do that from relatively simple to complex. See Jon Skeet's comprehensive review here: [^].
You don't need the "new"
redcupSkinManager = RedCupSkinManager.Instance;
这篇关于错误:类型名称“实例”不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!