Contents tagged with Override

  • Override Equals method of value types

    Hello everybody.

    Today I want to give some demo.

    using System;

    using System.Diagnostics;

    namespace StackOverflowQuest

    {

    class Program

    {

    struct StructTest

    {

    public string TestString { get; set; }

    //public override bool Equals(object obj)

    //{

    // var ct = (StructTest)obj;

    // return ct.TestString == this.TestString;

    //}

    }

    class ClassTest

    {

    public string TestString { get; set; }

    public override bool Equals(object obj)

    {

    var ct = obj as ClassTest;

    if (ct == null) … more