Click here to Skip to main content
15,916,600 members
Home / Discussions / C#
   

C#

 
AnswerRe: Unable to set registry value Pin
dusty_dex14-Mar-13 5:07
dusty_dex14-Mar-13 5:07 
QuestionHow to use CreateTextServices in C# Pin
cpw999cn13-Mar-13 20:32
cpw999cn13-Mar-13 20:32 
AnswerRe: How to use CreateTextServices in C# Pin
Bernhard Hiller13-Mar-13 22:01
Bernhard Hiller13-Mar-13 22:01 
GeneralRe: How to use CreateTextServices in C# Pin
cpw999cn13-Mar-13 22:40
cpw999cn13-Mar-13 22:40 
QuestionC# Receive from TCP send to COM2 Pin
dockwomblejr13-Mar-13 11:55
dockwomblejr13-Mar-13 11:55 
AnswerRe: C# Receive from TCP send to COM2 Pin
jschell14-Mar-13 7:57
jschell14-Mar-13 7:57 
GeneralRe: C# Receive from TCP send to COM2 Pin
dockwomblejr14-Mar-13 13:05
dockwomblejr14-Mar-13 13:05 
GeneralRe: C# Receive from TCP send to COM2 Pin
micke.andersson15-Mar-13 6:03
micke.andersson15-Mar-13 6:03 
Questionhow can i index files in c# Pin
Member 888804413-Mar-13 10:26
Member 888804413-Mar-13 10:26 
AnswerRe: how can i index files in c# Pin
R. Giskard Reventlov13-Mar-13 10:40
R. Giskard Reventlov13-Mar-13 10:40 
QuestionSplit with Regex Pin
Revolty13-Mar-13 8:21
Revolty13-Mar-13 8:21 
AnswerRe: Split with Regex Pin
Dave Kreskowiak13-Mar-13 9:30
mveDave Kreskowiak13-Mar-13 9:30 
GeneralRe: Split with Regex Pin
SledgeHammer0113-Mar-13 9:33
SledgeHammer0113-Mar-13 9:33 
GeneralRe: Split with Regex Pin
Dave Kreskowiak13-Mar-13 9:46
mveDave Kreskowiak13-Mar-13 9:46 
AnswerRe: Split with Regex Pin
Revolty13-Mar-13 10:29
Revolty13-Mar-13 10:29 
QuestionProblem with override the operators Pin
VendorX13-Mar-13 6:35
VendorX13-Mar-13 6:35 
AnswerRe: Problem with override the operators Pin
Eddy Vluggen13-Mar-13 6:37
professionalEddy Vluggen13-Mar-13 6:37 
GeneralRe: Problem with override the operators Pin
VendorX13-Mar-13 6:47
VendorX13-Mar-13 6:47 
GeneralRe: Problem with override the operators Pin
Eddy Vluggen13-Mar-13 7:20
professionalEddy Vluggen13-Mar-13 7:20 
AnswerRe: Problem with override the operators Pin
Dave Kreskowiak13-Mar-13 6:48
mveDave Kreskowiak13-Mar-13 6:48 
AnswerRe: Problem with override the operators Pin
Richard MacCutchan13-Mar-13 7:24
mveRichard MacCutchan13-Mar-13 7:24 
AnswerRe: Problem with override the operators Pin
Pete O'Hanlon13-Mar-13 7:27
mvePete O'Hanlon13-Mar-13 7:27 
GeneralRe: Problem with override the operators Pin
VendorX13-Mar-13 7:49
VendorX13-Mar-13 7:49 
AnswerRe: Problem with override the operators Pin
DaveyM6913-Mar-13 9:02
professionalDaveyM6913-Mar-13 9:02 
A rough untested example of how I do this for a class (it's much simpler for a struct as it can never be null):
C#
// An immutable int wrapper class
public class SomeClass : IEquatable<SomeClass>
{
    private int index;

    public SomeClass(int index)
    {
        this.index = index;
    }

    public static bool operator ==(SomeClass instance, SomeClass other)
    {
        if(object.ReferenceEquals(instance, other))
            return true;
        if(object.ReferenceEquals(null, instance) || object.ReferenceEquals(null, other))
            return false;
        return instance.index == other.index;
    }
    public static bool operator !=(SomeClass instance, SomeClass other)
    {
        return !(instance == other);
    }

    public int Index
    {
        get { return index; }
    }

    public override bool Equals(object obj)
    {
        return Equals(obj as SomeClass);
    }
    public bool Equals(SomeClass other)
    {
        if(object.ReferenceEquals(null, other))
            return false;
        return index.Equals(other.index);
    }
    public override int GetHashCode()
    {
        return index;
    }
}

And a struct:
C#
// An immutable int wrapper struct
public struct SomeStruct : IEquatable<SomeStruct>
{
    private int index;

    public SomeStruct(int index)
    {
        this.index = index;
    }

    public static bool operator ==(SomeStruct instance, SomeStruct other)
    {
        return instance.index == other.index;
    }
    public static bool operator !=(SomeStruct instance, SomeStruct other)
    {
        return !(instance == other);
    }

    public int Index
    {
        get { return index; }
    }

    public override bool Equals(object obj)
    {
        if(obj is SomeStruct)
            return Equals((SomeStruct)obj);
        return false;
    }
    public bool Equals(SomeStruct other)
    {
        return index.Equals(other.index);
    }
    public override int GetHashCode()
    {
        return index;
    }
}

Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

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



AnswerRe: Problem with override the operators Pin
DaveyM6913-Mar-13 9:10
professionalDaveyM6913-Mar-13 9:10 

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.