lundi 28 mars 2016

C# Why does "If (Tuple == Class1.Tuple)" not work, but "If (Tuple.Item1 == Class1.Tuple.Item1 && Tuple.Item2 == Class1.Tuple.Item2)" does?

I've been teaching myself C# over the last few months, mostly through trial/error and lots of google/stackoverflow searches, and I'm a tad confused as to whats happening/not happening here. My only previous coding experience came from Udacity's CS101 course about 3+ years ago, which involved some basic Python, most of which I had forgotten by the time I started C#.

class Class1
{
    public Tuple<int, int> StoredLoc = Tuple.Create(12, 6);
}

public partial class MainWindow : Window
{
    Class1 Cls1 = new Class1();

    private bool CheckLocation(int x, int y) //x = 12, y = 6
    {
        Tuple<int, int> loc = Tuple.Create(x, y);
        //This Does Not work
        if (loc == Cls1.StoredLoc)
        {
            //Do Code
        }

        //This Does Work
        if (loc.Item1 == Cls1.StoredLoc.Item1 && loc.Item2 == Cls1.StoredLoc.Item2)
        {
            //Do code
        }
    }
} 

What am I missing here? Why does loc == Cls1.StoredLoc not work?

Aucun commentaire:

Enregistrer un commentaire