TimeZoneInfo.AdjustmentRule.Equals Yöntem

Tanım

Aşırı Yüklemeler

Equals(Object)

Geçerli örneğin başka bir örneğe eşit olup olmadığını gösterir.

Equals(TimeZoneInfo+AdjustmentRule)

Geçerli TimeZoneInfo.AdjustmentRule nesnenin ikinci TimeZoneInfo.AdjustmentRule bir nesneye eşit olup olmadığını belirler.

Equals(Object)

Kaynak:
TimeZoneInfo.AdjustmentRule.cs
Kaynak:
TimeZoneInfo.AdjustmentRule.cs
Kaynak:
TimeZoneInfo.AdjustmentRule.cs

Geçerli örneğin başka bir örneğe eşit olup olmadığını gösterir.

C#
public override bool Equals(object? obj);

Parametreler

obj
Object

Bu örnekle karşılaştıracak bir örnek.

Döndürülenler

true geçerli örnek diğer örneğe eşitse; aksi takdirde , false.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET 7, 8, 9, 10

Equals(TimeZoneInfo+AdjustmentRule)

Kaynak:
TimeZoneInfo.AdjustmentRule.cs
Kaynak:
TimeZoneInfo.AdjustmentRule.cs
Kaynak:
TimeZoneInfo.AdjustmentRule.cs

Geçerli TimeZoneInfo.AdjustmentRule nesnenin ikinci TimeZoneInfo.AdjustmentRule bir nesneye eşit olup olmadığını belirler.

C#
public bool Equals(TimeZoneInfo.AdjustmentRule? other);
C#
public bool Equals(TimeZoneInfo.AdjustmentRule other);

Parametreler

other
TimeZoneInfo.AdjustmentRule

Geçerli nesneyle karşılaştırılacak nesne.

Döndürülenler

true her iki nesne de TimeZoneInfo.AdjustmentRule eşit değerlere sahipse; değilse, false.

Uygulamalar

Örnekler

Aşağıdaki örnek, Orta Standart Saat ayarlama kurallarını Kanada Orta Standart Saati ve Meksika Standart Saati ile karşılaştırmak için yöntemini çağırır TimeZoneInfo.AdjustmentRule.Equals(TimeZoneInfo+AdjustmentRule) .

C#
   string timeZoneName = "";
   // Get CST, Canadian CST, and Mexican CST adjustment rules
   TimeZoneInfo.AdjustmentRule[] usCstAdjustments = null;
   TimeZoneInfo.AdjustmentRule[] canCstAdjustments = null;
   TimeZoneInfo.AdjustmentRule[] mexCstAdjustments = null;
   try
   {
      timeZoneName = "Central Standard Time";
      usCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules();
   }
   catch (TimeZoneNotFoundException)
   {
      Console.WriteLine("The {0} time zone is not defined in the registry.", 
                        timeZoneName);
   }                           
   catch (InvalidTimeZoneException)
   {
      Console.WriteLine("Data for the {0} time zone is invalid.", 
                        timeZoneName);
   }
   try
   {
      timeZoneName = "Canada Central Standard Time";
      canCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules();
   }
   catch (TimeZoneNotFoundException)
   {
      Console.WriteLine("The {0} time zone is not defined in the registry.", 
                        timeZoneName);
   }                           
   catch (InvalidTimeZoneException)
   {
      Console.WriteLine("Data for the {0} time zone is invalid.", 
                        timeZoneName);
   }
   try
   {
      timeZoneName = "Central Standard Time (Mexico)";
      mexCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules();
   }   
   catch (TimeZoneNotFoundException)
   {
      Console.WriteLine("The {0} time zone is not defined in the registry.", 
                        timeZoneName);
   }                           
   catch (InvalidTimeZoneException)
   {
      Console.WriteLine("Data for the {0} time zone is invalid.", 
                        timeZoneName);
   }
   // Determine if CST and other time zones have the same rules
   foreach(TimeZoneInfo.AdjustmentRule rule in usCstAdjustments)
   {
      Console.WriteLine("Comparing Central Standard Time rule for {0:d} to {1:d} with:", 
                        rule.DateStart, rule.DateEnd);
      // Compare with Canada Central Standard Time
      if (canCstAdjustments.Length == 0)
      {
         Console.WriteLine("   Canada Central Standard Time has no adjustment rules.");
      }   
      else
      {
         foreach (TimeZoneInfo.AdjustmentRule canRule in canCstAdjustments)
         {
            Console.WriteLine("   Canadian CST for {0:d} to {1:d}: {2}", 
                              canRule.DateStart, canRule.DateEnd, 
                              rule.Equals(canRule) ? "Equal" : "Not Equal");
         }              
      }          

      // Compare with Mexico Central Standard Time
      if (mexCstAdjustments.Length == 0)
      {
         Console.WriteLine("   Mexican Central Standard Time has no adjustment rules.");
      }
      else
      {
         foreach (TimeZoneInfo.AdjustmentRule mexRule in mexCstAdjustments)
         {
            Console.WriteLine("   Mexican CST for {0:d} to {1:d}: {2}", 
                              mexRule.DateStart, mexRule.DateEnd, 
                              rule.Equals(mexRule) ? "Equal" : "Not Equal");
         }              
      }
   }   
   // This code displays the following output to the console:
   // 
   // Comparing Central Standard Time rule for 1/1/0001 to 12/31/9999 with:
   //    Canada Central Standard Time has no adjustment rules.
   //    Mexican CST for 1/1/0001 to 12/31/9999: Equal

Bu kod konsolda aşağıdaki çıkışı görüntüler:

Comparing Central Standard Time rule for 1/1/0001 to 12/31/9999 with:  
   Canada Central Standard Time has no adjustment rules.  
   Mexican CST for 1/1/0001 to 12/31/9999: Equal  

Açıklamalar

İki TimeZoneInfo.AdjustmentRule nesnenin Equals(TimeZoneInfo+AdjustmentRule) eşit olup olmadığını belirlemek için yöntemi her nesnenin üye değerlerini karşılaştırır. İki ayarlama kuralı, ve özellikleri tarafından DaylightTransitionStartDaylightTransitionEnd döndürülen nesneler için aynı geçerlilik tarihlerine, aynı deltaya ve aynı değerlere TimeZoneInfo.TransitionTime sahipse eşittir.

Şunlara uygulanır

.NET 10 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1