MyGuid.Equals (OtherGuid) NOT EQUAL?

When I use MyGuid.ToString (). Equals (OtherGuid.ToString ())

they are equal, why are they not equal when I compare pure guid?

Update:

Well, the problem here is that I am using a third-party control.

The key below is Guid and CommitteeId is also Guid. They were never equal only when I did

ToString () on both Guid` they were equal, which is odd.

 for (int i = 0; i < this.ultraCalendarInfo.Owners.Count; i++) 
                if (ultraCalendarInfo.Owners[i].Key.ToString().Equals(committeeId))
                    ultraCalendarInfo.Owners[i].Visible = isVisible; 
+3
source share
3 answers

I can not reproduce the problem:

using System;

class Program
{
    static void Main(string[] args)
    {
        Guid x = Guid.NewGuid();
        Guid y = new Guid(x.ToString());

        Console.WriteLine(x == y);
        Console.WriteLine(x.Equals(y));
        Console.WriteLine(x.ToString() == y.ToString());
    }
}

It produces:

True
True
True

Please give a similar short but complete program that demonstrates the problem.

EDIT: I think I see the problem now, and this is in your code:

if (ultraCalendarInfo.Owners[i].Key.ToString().Equals(committeeId))

You stated:

.Key Guid committeeId Guid.

ToString() Guid, committeeId, . ToString() , , .

, ( - , ) . ToString() (.. guid.ToString().ToString() ..) , , - , ToString() (0 1 ), "" ... ToString() - .

+11

object g1 = Guid.NewGuid();
object g2 = new Guid(((Guid)g1).ToByteArray());
Console.WriteLine("{0}\r\n{1}", g1, g2);
Console.WriteLine("   Equals: {0}", g1.Equals(g2));
Console.WriteLine("Object ==: {0}", g1 == g2);
Console.WriteLine(" Value ==: {0}", (Guid)g1 == (Guid)g2);

GUID "" "" . "==" , , , , . , g1 g2 Guid, True . False "==". , "un-box" , , , . , , "", ( ) .

+2

, , , , ( SqlGuid ):

 Sub Main()

        Dim stringValue = Guid.NewGuid().ToString()

        Dim first = New Guid(stringValue)
        Dim second = New SqlTypes.SqlGuid(stringValue)

        Console.WriteLine(first = second)    'True'
        Console.WriteLine(first.Equals(second))    'False'
        Console.WriteLine(first.ToString() = second.ToString())    'True'
        Console.ReadKey()

    End Sub
0

Source: https://habr.com/ru/post/1760310/


All Articles