Click here to Skip to main content
15,894,646 members
Home / Discussions / C#
   

C#

 
GeneralRe: I thought singletons were "Evil"? Pin
LimitedAtonement15-Jun-10 2:55
LimitedAtonement15-Jun-10 2:55 
AnswerRe: I thought singletons were "Evil"? PinPopular
David Skelly15-Jun-10 2:02
David Skelly15-Jun-10 2:02 
AnswerRe: I thought singletons were "Evil"? Pin
PIEBALDconsult15-Jun-10 3:07
mvePIEBALDconsult15-Jun-10 3:07 
QuestionObject Null/Empty Check Pin
jojoba201114-Jun-10 22:31
jojoba201114-Jun-10 22:31 
AnswerRe: Object Null/Empty Check Pin
Peace ON14-Jun-10 22:44
Peace ON14-Jun-10 22:44 
AnswerRe: Object Null/Empty Check Pin
DaveyM6914-Jun-10 22:47
professionalDaveyM6914-Jun-10 22:47 
QuestionRe: Object Null/Empty Check Pin
jojoba201114-Jun-10 23:24
jojoba201114-Jun-10 23:24 
AnswerRe: Object Null/Empty Check Pin
DaveyM6915-Jun-10 0:46
professionalDaveyM6915-Jun-10 0:46 
OK, here's an example class. The implementation of the interface is the method at the end.
C#
public class IntString : IEmpty
{
    private string text;
    private int value;

    public IntString()
        : this(0, string.Empty)
    { }
    public IntString(int value)
        : this(value, string.Empty)
    { }
    public IntString(string text)
        : this(0, text)
    { }
    public IntString(int value, string text)
    {
        this.text = text;
        this.value = value;
    }

    public string Text
    {
        get { return text; }
        set { text = value; }
    }
    public int Value
    {
        get { return value; }
        set { this.value = value; }
    }

    // Interface implementation
    public bool IsEmpty
    {
        get { return value == 0 && string.IsNullOrEmpty(text); }
    }
}

To use it, combined with the method and interface declaration i posted earlier you can do something like this...
C#
IntString intString = new IntString();
Console.WriteLine(IsNullOrEmpty<IntString>(intString));

Dave

If this helped, please vote & accept answer!


Binging is like googling, it just feels dirtier. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

QuestionRe: Object Null/Empty Check Pin
jojoba201114-Jun-10 22:50
jojoba201114-Jun-10 22:50 
AnswerRe: Object Null/Empty Check Pin
DaveyM6914-Jun-10 23:00
professionalDaveyM6914-Jun-10 23:00 
QuestionRe: Object Null/Empty Check Pin
jojoba201114-Jun-10 23:23
jojoba201114-Jun-10 23:23 
GeneralRe: Object Null/Empty Check Pin
Luc Pattyn15-Jun-10 0:55
sitebuilderLuc Pattyn15-Jun-10 0:55 
GeneralRe: Object Null/Empty Check Pin
DaveyM6915-Jun-10 1:07
professionalDaveyM6915-Jun-10 1:07 
AnswerRe: Object Null/Empty Check Pin
Eddy Vluggen14-Jun-10 23:04
professionalEddy Vluggen14-Jun-10 23:04 
QuestionAuto Generate Row Number [solved] Pin
Elango N14-Jun-10 22:12
Elango N14-Jun-10 22:12 
AnswerRe: Auto Generate Row Number Pin
Peace ON14-Jun-10 22:29
Peace ON14-Jun-10 22:29 
Questionhow I could save apicture in sql and bring it to a form in C#? Pin
ronakT14-Jun-10 21:34
ronakT14-Jun-10 21:34 
AnswerRe: how I could save apicture in sql and bring it to a form in C#? Pin
Abhinav S14-Jun-10 22:12
Abhinav S14-Jun-10 22:12 
QuestionHaving A Spot Of Trouble With Events Pin
Roger Wright14-Jun-10 19:48
professionalRoger Wright14-Jun-10 19:48 
AnswerRe: Having A Spot Of Trouble With Events Pin
TheFoZ14-Jun-10 21:28
TheFoZ14-Jun-10 21:28 
GeneralRe: Having A Spot Of Trouble With Events Pin
Roger Wright15-Jun-10 7:06
professionalRoger Wright15-Jun-10 7:06 
AnswerRe: Having A Spot Of Trouble With Events Pin
DaveyM6914-Jun-10 22:21
professionalDaveyM6914-Jun-10 22:21 
QuestionTrackBar Pin
Nicolás Marzoni14-Jun-10 17:32
Nicolás Marzoni14-Jun-10 17:32 
AnswerRe: TrackBar Pin
Calla14-Jun-10 19:32
Calla14-Jun-10 19:32 
GeneralRe: TrackBar Pin
Nicolás Marzoni15-Jun-10 1:28
Nicolás Marzoni15-Jun-10 1:28 

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.