Singleton类的构造函数 [英] Constructors in Singleton Class

查看:69
本文介绍了Singleton类的构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用Singleton类时,请原谅我对此的无知。我需要使用它来运行我的Class的一个实例,我想我知道如何执行此操作。
了解如何执行此操作。我的问题是,单身人士课程是否可以使用
a数量的参数化构造函数,使我能够传递参数或

不是吗?


我试图使用以下内容将parmeter发送给构造函数,但

得到错误。我有一种感觉,我无法做到这一点。是

还有其他方法可以做到这一点。


Dim sPatName As String =" Green"

Dim EMP由于CEmPacc = CEmPacc.Create(sPatName)


类myApp.CEmPacc无法编入索引,因为它没有默认属性


非常感谢


Paul Bromley

解决方案

像往常一样,发布一个问题让我想到了一个可能的答案。我是通过访问我的

类中的属性并传入随后在我的属性中使用的参数来解决下面的问题。我认为

这是允许的吗?我知道这是一个愚蠢的问题,但我也认为
假设我的单身人士课程中可以有很多属性,因为我可以在任何其他课程中获得
- 我有只见了Singleton

班的非常基本的例子。


谢谢


Paul Bromley

Paul Bromley < FL ******* @ dsl.pipex.com>在消息中写道

news:uB ************** @ TK2MSFTNGP10.phx.gbl ...

原谅我对此的无知因为我正在尝试使用Singleton类。
我需要使用它来运行我的类的一个实例,我想我明白了如何做到这一点。我的问题是,单例类
有多个参数化的构造函数,使我能够传入参数或
不是吗?

我试图使用以下内容发送一个parmeter到构造函数,
但是得到了一个错误。我有一种感觉,我无法做到这一点。
有没有其他方法可以做到这一点。

Dim sPatName As String =" Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

类myApp.CEmPacc无法编入索引,因为它没有默认属性

非常感谢

Paul Bromley



Paul,


您可以像对常规的

类一样向单例类添加属性。


-

Mike


Mike McIntyre

Visual Basic MVP
www.getdotnetcode.com

" Paul Bromley" < FL ******* @ dsl.pipex.com>在留言中写道

新闻:e6 ************** @ TK2MSFTNGP14.phx.gbl ...

像往常一样,张贴一个问题让我想到了一个可能的答案。我通过访问我的
类中的属性并传入随后在我的属性中使用的参数来解决下面的问题。我承认
这是允许的吗?我知道这是一个愚蠢的问题,但是我也认为我可以在我的单身课程中拥有许多属性,因为我会选择任何其他课程 - 我只看到非常基本的Singleton
类的例子。

谢谢

Paul Bromley

" Paul Bromley" < FL ******* @ dsl.pipex.com>在消息中写道
新闻:uB ************** @ TK2MSFTNGP10.phx.gbl ...

原谅我对这一个的无知,因为我尝试使用Singleton类。


需要使用它来运行我的类的一个实例,我想我明白了如何做到这一点。我的问题是,单例类


一些参数化构造函数,使我能够传递参数

不是吗?
我正在尝试使用以下命令将parmeter发送给构造函数,


使用它获取错误。我有一种感觉,我无法做到这一点。


还有其他方法可以做到这一点。

Dim sPatName As String =" Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

类myApp.CEmPacc无法编入索引,因为它没有默认属性
非常感谢

Paul Bromley




谢谢Mike。


Paul

" Mike McIntyre [MVP]" < MI **** @ getdotnetcode.com>在消息中写道

新闻:关于************** @ TK2MSFTNGP15.phx.gbl ...

Paul,
您可以像对普通课程一样为单身课程添加属性。

-
迈克

迈克McIntyre
Visual Basic MVP
www.getdotnetcode.com
" Paul Bromley" < FL ******* @ dsl.pipex.com>在消息中写道
新闻:e6 ************** @ TK2MSFTNGP14.phx.gbl ...

像往常一样,发帖提问我想一想可能的答案。
我通过访问我的
类中的属性并传入随后在我的属性中使用的参数来解决我在下面遇到的问题。我承认
这是允许的吗?我知道这是一个愚蠢的问题,但是我也认为我可以在我的单身课程中拥有许多属性,因为我会选择任何其他课程 - 我只看到非常基本的
单身人士课程的例子。

感谢

Paul Bromley

" Paul Bromley" < FL ******* @ dsl.pipex.com>在消息中写道
新闻:uB ************** @ TK2MSFTNGP10.phx.gbl ...

原谅我对这一个的无知,因为我试图使用Singleton
类。

我需要使用它来运行我的Class的一个实例我想我明白该怎么做。我的问题是,单例类


一些参数化构造函数,使我能够传递参数

不是吗?
我正在尝试使用以下命令将parmeter发送到


构造函数,但

使用它获取错误。我有一种感觉,我无法做到


这个。

还有其他方法可以做到这一点。

Dim sPatName As String =" Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName) )

类myApp.CEmPacc无法编入索引,因为它没有默认值



属性
非常感谢

Paul Bromley





Forgive my ignorance on this one as I am trying to use a Singleton class. I
need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class have
a number of paramterised constructors enabling me to pass in parameters or
not?

I am trying to use the following to send in a parmeter to a constructor, but
getting an error with it. I have a feeling that I am not able to do this. Is
there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley

解决方案

As usual, posting a question has made me think about a possible answer. I am
getting around the problem that I had below by accesing a property in my
class and passing in parameters that are then used in my property. I assume
that this is permissible? I know that this is a stupid question, but I also
assume that I can have a number of properties in my singleton class as I
would any other class - I have only seen very basic examples of Singleton
classes.

Thanks

Paul Bromley
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...

Forgive my ignorance on this one as I am trying to use a Singleton class. I need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class have a number of paramterised constructors enabling me to pass in parameters or
not?

I am trying to use the following to send in a parmeter to a constructor, but getting an error with it. I have a feeling that I am not able to do this. Is there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley



Paul,

You can add properties to a singleton class just as you would to a regular
class.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:e6**************@TK2MSFTNGP14.phx.gbl...

As usual, posting a question has made me think about a possible answer. I
am
getting around the problem that I had below by accesing a property in my
class and passing in parameters that are then used in my property. I
assume
that this is permissible? I know that this is a stupid question, but I
also
assume that I can have a number of properties in my singleton class as I
would any other class - I have only seen very basic examples of Singleton
classes.

Thanks

Paul Bromley
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...

Forgive my ignorance on this one as I am trying to use a Singleton class.


I

need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class


have

a number of paramterised constructors enabling me to pass in parameters
or
not?

I am trying to use the following to send in a parmeter to a constructor,


but

getting an error with it. I have a feeling that I am not able to do this.


Is

there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default property

Many thanks

Paul Bromley




Thanks Mike.

Paul
"Mike McIntyre [MVP]" <mi****@getdotnetcode.com> wrote in message
news:On**************@TK2MSFTNGP15.phx.gbl...

Paul,

You can add properties to a singleton class just as you would to a regular
class.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:e6**************@TK2MSFTNGP14.phx.gbl...

As usual, posting a question has made me think about a possible answer. I am
getting around the problem that I had below by accesing a property in my
class and passing in parameters that are then used in my property. I
assume
that this is permissible? I know that this is a stupid question, but I
also
assume that I can have a number of properties in my singleton class as I
would any other class - I have only seen very basic examples of Singleton classes.

Thanks

Paul Bromley
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...

Forgive my ignorance on this one as I am trying to use a Singleton class.

I

need to use this to have one instance of my Class running and I think I
understand how to do this. My question however is can a singleton class


have

a number of paramterised constructors enabling me to pass in parameters
or
not?

I am trying to use the following to send in a parmeter to a

constructor, but

getting an error with it. I have a feeling that I am not able to do

this. Is

there any other way that I can do this.

Dim sPatName As String = "Green"
Dim EMP As CEmPacc = CEmPacc.Create(sPatName)

Class myApp.CEmPacc cannot be indexed because it has no default


property
Many thanks

Paul Bromley





这篇关于Singleton类的构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆