Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

TimeZoneInfo.AdjustmentRule.Equals-Methode: (TimeZoneInfo.AdjustmentRule)

 

Veröffentlicht: Oktober 2016

Bestimmt, ob das aktuelle TimeZoneInfo.AdjustmentRule-Objekt und das zweite TimeZoneInfo.AdjustmentRule-Objekt identisch sind.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public bool Equals(
	TimeZoneInfo.AdjustmentRule other
)

Parameter

other
Type: System.TimeZoneInfo.AdjustmentRule

Das Objekt, das mit dem aktuellen Objekt verglichen werden soll.

Rückgabewert

Type: System.Boolean

true, wenn beide TimeZoneInfo.AdjustmentRule-Objekte gleiche Werte aufweisen, andernfalls false.

To determine whether two T:System.TimeZoneInfo.AdjustmentRule objects are equal, the M:System.TimeZoneInfo.AdjustmentRule.Equals(System.TimeZoneInfo.AdjustmentRule) method compares the member values of each object. Two adjustment rules are equal if they have the same effective dates, the same delta, and identical values for the T:System.TimeZoneInfo.TransitionTime objects returned by their P:System.TimeZoneInfo.AdjustmentRule.DaylightTransitionStart and P:System.TimeZoneInfo.AdjustmentRule.DaylightTransitionEnd properties.

The following example calls the M:System.TimeZoneInfo.AdjustmentRule.Equals(System.TimeZoneInfo.AdjustmentRule) method to compare the adjustment rules for Central Standard Time with those for Canada Central Standard Time and Mexico Standard Time.

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

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

.NET Framework
Verfügbar seit 3.5
Zurück zum Anfang
Anzeigen: