Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Metodo TimeZoneInfo.AdjustmentRule.Equals (TimeZoneInfo.AdjustmentRule)

 

Data di pubblicazione: ottobre 2016

Determina se l'oggetto TimeZoneInfo.AdjustmentRule corrente è uguale a un secondo oggetto TimeZoneInfo.AdjustmentRule.

Spazio dei nomi:   System
Assembly:  mscorlib (in mscorlib.dll)

public bool Equals(
	TimeZoneInfo.AdjustmentRule other
)

Parametri

other
Type: System.TimeZoneInfo.AdjustmentRule

Oggetto da confrontare con l'oggetto corrente.

Valore restituito

Type: System.Boolean

true se entrambi gli oggetti TimeZoneInfo.AdjustmentRule hanno valori uguali. In caso contrario, 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
Disponibile da 3.5
Torna all'inizio
Mostra: