Click here to Skip to main content
15,906,816 members
Home / Discussions / C#
   

C#

 
QuestionBarcode for & Sign....? Pin
NetMan201226-May-10 22:40
NetMan201226-May-10 22:40 
AnswerRe: Barcode for & Sign....? Pin
Eddy Vluggen26-May-10 22:45
professionalEddy Vluggen26-May-10 22:45 
AnswerRe: Barcode for & Sign....? Pin
OriginalGriff27-May-10 1:06
mveOriginalGriff27-May-10 1:06 
AnswerRe: Barcode for & Sign....? [modified] Pin
Luc Pattyn27-May-10 3:25
sitebuilderLuc Pattyn27-May-10 3:25 
QuestionMessage Removed Pin
26-May-10 22:13
jainiraj26-May-10 22:13 
AnswerRe: change look of controls in VS 2005 C# Pin
Johnny J.26-May-10 22:28
professionalJohnny J.26-May-10 22:28 
QuestionRestricting class creating only 3 objects Pin
Member 352189226-May-10 20:37
Member 352189226-May-10 20:37 
AnswerRe: Restricting class creating only 3 objects [modified] PinPopular
Jens Meyer26-May-10 21:11
Jens Meyer26-May-10 21:11 
Use a Singleton-like approach. Make the constructor private and add a static method. In this method return a new instance of the class when a static counter is less than 3 (starting with 0). Then increment the counter.

If the counter is >2 do what ever you like to do if the third instance is delivered.

Small example:

<br />
public class MyRestrictedClass<br />
    {<br />
        private static int instanceCounter = 0;<br />
        private MyRestrictedClass()<br />
        {<br />
            //cool ctor stuff<br />
        }<br />
<br />
        public MyRestrictedClass GetNextInstance()<br />
        {<br />
            if(instanceCounter<=2)<br />
            {<br />
                instanceCounter++;<br />
                return new MyRestrictedClass();<br />
            }<br />
            throw new Exception("Maximum number of instances exceeded.");<br />
        }<br />
    }<br />


Best regards

Jens
When in trouble,
when in doubt,
run in circles,
scream and shout
modified on Thursday, May 27, 2010 3:18 AM

GeneralRe: Restricting class creating only 3 objects Pin
Member 352189228-May-10 1:25
Member 352189228-May-10 1:25 
QuestionHow to create multiple copies of single document. Pin
Exelioindia26-May-10 19:17
Exelioindia26-May-10 19:17 
AnswerRe: How to create multiple copies of single document. Pin
Eddy Vluggen26-May-10 22:51
professionalEddy Vluggen26-May-10 22:51 
QuestionRegarding look of window forms controls.... Pin
jainiraj26-May-10 18:24
jainiraj26-May-10 18:24 
AnswerRe: Regarding look of window forms controls.... Pin
Dave Kreskowiak26-May-10 18:56
mveDave Kreskowiak26-May-10 18:56 
GeneralRe: Regarding look of window forms controls.... Pin
jainiraj26-May-10 19:24
jainiraj26-May-10 19:24 
AnswerRe: Regarding look of window forms controls.... Pin
Abhinav S26-May-10 19:05
Abhinav S26-May-10 19:05 
AnswerRe: Regarding look of window forms controls.... Pin
Johnny J.26-May-10 21:04
professionalJohnny J.26-May-10 21:04 
AnswerRe: Regarding look of window forms controls.... Pin
Johnny J.26-May-10 22:30
professionalJohnny J.26-May-10 22:30 
GeneralRe: Regarding look of window forms controls.... Pin
jainiraj26-May-10 22:36
jainiraj26-May-10 22:36 
QuestionZip/Unzip Pin
jojoba201126-May-10 17:21
jojoba201126-May-10 17:21 
AnswerRe: Zip/Unzip Pin
Luc Pattyn26-May-10 17:42
sitebuilderLuc Pattyn26-May-10 17:42 
GeneralRe: Zip/Unzip Pin
Bernhard Hiller26-May-10 23:20
Bernhard Hiller26-May-10 23:20 
GeneralRe: Zip/Unzip Pin
Luc Pattyn27-May-10 3:15
sitebuilderLuc Pattyn27-May-10 3:15 
QuestionProblem in use Of ReaderWriterLockSlim Class Pin
shahramkeyboard26-May-10 11:14
shahramkeyboard26-May-10 11:14 
AnswerRe: Problem in use Of ReaderWriterLockSlim Class Pin
Henry Minute26-May-10 11:43
Henry Minute26-May-10 11:43 
AnswerRe: Problem in use Of ReaderWriterLockSlim Class Pin
William Winner26-May-10 12:22
William Winner26-May-10 12:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.