Click here to Skip to main content
15,901,035 members
Home / Discussions / C#
   

C#

 
GeneralRe: Code Readability Poll Pin
Luc Pattyn7-Oct-09 9:14
sitebuilderLuc Pattyn7-Oct-09 9:14 
GeneralRe: Code Readability Poll Pin
PIEBALDconsult7-Oct-09 12:58
mvePIEBALDconsult7-Oct-09 12:58 
AnswerRe: Code Readability Poll Pin
N a v a n e e t h7-Oct-09 6:42
N a v a n e e t h7-Oct-09 6:42 
GeneralRe: Code Readability Poll Pin
PIEBALDconsult7-Oct-09 7:32
mvePIEBALDconsult7-Oct-09 7:32 
GeneralRe: Code Readability Poll Pin
N a v a n e e t h7-Oct-09 7:42
N a v a n e e t h7-Oct-09 7:42 
GeneralRe: Code Readability Poll Pin
DaveyM697-Oct-09 9:08
professionalDaveyM697-Oct-09 9:08 
GeneralRe: Code Readability Poll Pin
LimitedAtonement7-Oct-09 10:02
LimitedAtonement7-Oct-09 10:02 
GeneralRe: Code Readability Poll [modified] Pin
DaveyM697-Oct-09 11:12
professionalDaveyM697-Oct-09 11:12 
I meant within the class itself. Consider this int wrapper class (I've just written it out quickly so is very rough!) and compare the two different == operator overloads...
C#
public class MyIntWrapperClass : IEquatable<MyIntWrapperClass>
{
    private int _Value;
    public MyIntWrapperClass(int value)
    {
        _Value = value;
    }

    // This method will throw a null reference exception if either parameter is null
    /* public static bool operator ==(MyIntWrapperClass a, MyIntWrapperClass b)
    {
        return a._Value == b._Value;
    }*/

    // This method works if either is null. If both are null, returns true.
    public static bool operator ==(MyIntWrapperClass a, MyIntWrapperClass b)
    {
        bool result = false;
        if (!ReferenceEquals(a, null))
        {
            if (!ReferenceEquals(b, null))
                result = a._Value == b._Value; // neither are null so compare _Value
            else
                result = false; // b is null but a isn't
        }
        else
            result = ReferenceEquals(b, null); // true if both are null
        return result;
    }
    public static bool operator !=(MyIntWrapperClass a, MyIntWrapperClass b)
    {
        return !(a == b);
    }
    public int Value
    {
        get { return _Value; }
    }
    public override bool Equals(object obj)
    {
        return Equals(obj as MyIntWrapperClass);
    }
    public bool Equals(MyIntWrapperClass other)
    {
        // using == overload
        return this == other;
    }
    public override int GetHashCode()
    {
        return _Value; ;
    }
    public override string ToString()
    {
        return _Value.ToString();
    }
}


Dave

Generic BackgroundWorker - My latest article!
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

modified on Wednesday, October 7, 2009 5:24 PM

AnswerRe: Code Readability Poll Pin
Not Active7-Oct-09 6:44
mentorNot Active7-Oct-09 6:44 
GeneralRe: Code Readability Poll Pin
Kevin Marois7-Oct-09 6:53
professionalKevin Marois7-Oct-09 6:53 
GeneralRe: Code Readability Poll Pin
N a v a n e e t h7-Oct-09 7:24
N a v a n e e t h7-Oct-09 7:24 
GeneralRe: Code Readability Poll Pin
Not Active7-Oct-09 7:53
mentorNot Active7-Oct-09 7:53 
GeneralRe: Code Readability Poll Pin
PIEBALDconsult7-Oct-09 7:54
mvePIEBALDconsult7-Oct-09 7:54 
GeneralRe: Code Readability Poll Pin
LimitedAtonement7-Oct-09 7:32
LimitedAtonement7-Oct-09 7:32 
GeneralRe: Code Readability Poll Pin
Not Active7-Oct-09 8:01
mentorNot Active7-Oct-09 8:01 
GeneralRe: Code Readability Poll Pin
PIEBALDconsult7-Oct-09 8:07
mvePIEBALDconsult7-Oct-09 8:07 
GeneralRe: Code Readability Poll Pin
PIEBALDconsult7-Oct-09 7:40
mvePIEBALDconsult7-Oct-09 7:40 
AnswerRe: Code Readability Poll Pin
PIEBALDconsult7-Oct-09 7:26
mvePIEBALDconsult7-Oct-09 7:26 
AnswerRe: Code Readability Poll Pin
PIEBALDconsult7-Oct-09 8:41
mvePIEBALDconsult7-Oct-09 8:41 
AnswerRe: Code Readability Poll Pin
OriginalGriff7-Oct-09 10:35
mveOriginalGriff7-Oct-09 10:35 
GeneralRe: Code Readability Poll Pin
PIEBALDconsult7-Oct-09 13:22
mvePIEBALDconsult7-Oct-09 13:22 
QuestionPocket PC development tools Pin
libelledriver7-Oct-09 4:21
libelledriver7-Oct-09 4:21 
AnswerRe: Pocket PC development tools Pin
EliottA7-Oct-09 4:24
EliottA7-Oct-09 4:24 
GeneralRe: Pocket PC development tools Pin
libelledriver9-Oct-09 3:25
libelledriver9-Oct-09 3:25 
GeneralRe: Pocket PC development tools Pin
EliottA9-Oct-09 3:27
EliottA9-Oct-09 3:27 

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.