TimeZoneInfo.AdjustmentRule.Equals 메서드

정의

오버로드

Equals(Object)

현재 인스턴스가 다른 인스턴스와 같은지 여부를 나타냅니다.

Equals(TimeZoneInfo+AdjustmentRule)

현재 TimeZoneInfo.AdjustmentRule 개체가 두 번째 TimeZoneInfo.AdjustmentRule 개체와 같은지 확인합니다.

Equals(Object)

현재 인스턴스가 다른 인스턴스와 같은지 여부를 나타냅니다.

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object? obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

매개 변수

obj
Object

이 인스턴스와 비교할 인스턴스입니다.

반환

Boolean

true현재 인스턴스가 다른 인스턴스와 같으면 이고, 그렇지 않으면 . false

적용 대상

Equals(TimeZoneInfo+AdjustmentRule)

현재 TimeZoneInfo.AdjustmentRule 개체가 두 번째 TimeZoneInfo.AdjustmentRule 개체와 같은지 확인합니다.

public:
 virtual bool Equals(TimeZoneInfo::AdjustmentRule ^ other);
public bool Equals (TimeZoneInfo.AdjustmentRule? other);
public bool Equals (TimeZoneInfo.AdjustmentRule other);
override this.Equals : TimeZoneInfo.AdjustmentRule -> bool
Public Function Equals (other As TimeZoneInfo.AdjustmentRule) As Boolean

매개 변수

other
TimeZoneInfo.AdjustmentRule

현재 개체와 비교할 개체입니다.

반환

Boolean

TimeZoneInfo.AdjustmentRule 개체의 값이 같으면 true, 같지 않으면 false입니다.

구현

예제

다음 예제에서는 중앙 표준시에 대한 조정 규칙을 캐나다 중부 표준시 및 멕시코 표준시 조정 규칙과 비교하는 메서드를 호출 TimeZoneInfo.AdjustmentRule.Equals(TimeZoneInfo+AdjustmentRule) 합니다.

   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
// Get CST, Canadian CST, and Mexican CST adjustment rules
let usCstAdjustments =
    let timeZoneName = "Central Standard Time"
    try
        TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules()
    with
    | :? TimeZoneNotFoundException ->
        printfn $"The {timeZoneName} time zone is not defined in the registry."
        null
    | :? InvalidTimeZoneException ->
        printfn $"Data for the {timeZoneName} time zone is invalid."
        null
let canCstAdjustments = 
    let timeZoneName = "Canada Central Standard Time"
    try
        TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules()
    with
    | :? TimeZoneNotFoundException ->
        printfn $"The {timeZoneName} time zone is not defined in the registry."
        null
    | :? InvalidTimeZoneException ->
        printfn $"Data for the {timeZoneName} time zone is invalid."
        null
let mexCstAdjustments = 
    let timeZoneName = "Central Standard Time (Mexico)"
    try
        TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules()
    with
    | :? TimeZoneNotFoundException ->
        printfn $"The {timeZoneName} time zone is not defined in the registry."
        null
    | :? InvalidTimeZoneException ->
        printfn $"Data for the {timeZoneName} time zone is invalid."
        null
// Determine if CST and other time zones have the same rules
for rule in usCstAdjustments do
    printfn $"Comparing Central Standard Time rule for {rule.DateStart:d} to {rule.DateEnd:d} with:"
    // Compare with Canada Central Standard Time
    if canCstAdjustments.Length = 0 then
        printfn "   Canada Central Standard Time has no adjustment rules."
    else
        for canRule in canCstAdjustments do
            printfn $"""   Canadian CST for {canRule.DateStart:d} to {canRule.DateEnd:d}: {if rule.Equals canRule then "Equal" else "Not Equal"}"""

    // Compare with Mexico Central Standard Time
    if mexCstAdjustments.Length = 0 then
        printfn "   Mexican Central Standard Time has no adjustment rules."
    else
        for mexRule in mexCstAdjustments do
            printfn $"""   Mexican CST for {mexRule.DateStart:d} to {mexRule.DateEnd:d}: {if rule.Equals mexRule then "Equal" else "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
   Dim timeZoneName As String = String.Empty
   ' Get CST, Canadian CST, and Mexican CST adjustment rules
   Dim usCstAdjustments(), canCstAdjustments(), mexCstAdjustments() As TimeZoneInfo.AdjustmentRule
   Try
      timeZoneName = "Central Standard Time"
      usCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules
   Catch e As TimeZoneNotFoundException
      Console.WriteLine("The {0} time zone is not defined in the registry.", timeZoneName)
   Catch e As InvalidTimeZoneException
      Console.WriteLine("Data for the {0} time zone is invalid.", timeZoneName)
   End Try
   Try
      timeZoneName = "Canada Central Standard Time"
      canCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules
   Catch e As TimeZoneNotFoundException
      Console.WriteLine("The {0} time zone is not defined in the registry.", timeZoneName)
   Catch e As InvalidTimeZoneException
      Console.WriteLine("Data for the {0} time zone is invalid.", timeZoneName)
   End Try
   Try
      timeZoneName = "Central Standard Time (Mexico)"
      mexCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules
   Catch e As TimeZoneNotFoundException
      Console.WriteLine("The {0} time zone is not defined in the registry.", timeZoneName)
   Catch e As InvalidTimeZoneException
      Console.WriteLine("Data for the {0} time zone is invalid.", timeZoneName)
   End Try
   ' Determine if CST and other time zones have the same rules
   For Each rule As TimeZoneInfo.AdjustmentRule 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 Then
         Console.WriteLine("   Canada Central Standard Time has no adjustment rules.")
      Else
         For Each canRule As TimeZoneInfo.AdjustmentRule In canCstAdjustments
            Console.WriteLine("   Canadian CST for {0:d} to {1:d}: {2}", _
                              canRule.DateStart, canRule.DateEnd, _
                              IIf(rule.Equals(canRule), "Equal", "Not Equal"))
         Next              
      End If          

      ' Compare with Mexico Central Standard Time
      If mexCstAdjustments.Length = 0 Then
         Console.WriteLine("   Mexican Central Standard Time has no adjustment rules.")
      Else
         For Each mexRule As TimeZoneInfo.AdjustmentRule In mexCstAdjustments
            Console.WriteLine("   Mexican CST for {0:d} to {1:d}: {2}", _
                              mexRule.DateStart, mexRule.DateEnd, _
                              IIf(rule.Equals(mexRule), "Equal", "Not Equal"))
         Next              
      End If
   Next   
   ' 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

이 코드는 콘솔에 다음 출력을 표시합니다.

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  

설명

TimeZoneInfo.AdjustmentRule 개체가 같은지 여부를 확인하기 위해 메서드는 Equals(TimeZoneInfo+AdjustmentRule) 각 개체의 멤버 값을 비교합니다. 두 조정 규칙은 유효 날짜가 같고 델타가 동일하며 해당 규칙과 속성에서 반환된 DaylightTransitionStart DaylightTransitionEnd 개체에 대해 TimeZoneInfo.TransitionTime 동일한 값이 있는 경우 동일합니다.

적용 대상