diff --git a/quest-config.json b/quest-config.json
index 438a990976d..8d4a9665c71 100644
--- a/quest-config.json
+++ b/quest-config.json
@@ -2,7 +2,7 @@
"AzureDevOps": {
"Org": "msft-skilling",
"Project": "Content",
- "AreaPath": "Production\\Digital and App Innovation\\DotNet and more\\dotnet"
+ "AreaPath": "Production\\Core AI\\DotNet and more\\dotnet"
},
"ImportTriggerLabel": ":world_map: reQUEST",
"ImportedLabel": ":pushpin: seQUESTered",
diff --git a/snippets/csharp/System/IEquatableT/Equals/Equals.csproj b/snippets/csharp/System/IEquatableT/Equals/Equals.csproj
new file mode 100644
index 00000000000..2150e3797ba
--- /dev/null
+++ b/snippets/csharp/System/IEquatableT/Equals/Equals.csproj
@@ -0,0 +1,10 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
diff --git a/snippets/csharp/System/IEquatableT/Equals/EqualsEx1.cs b/snippets/csharp/System/IEquatableT/Equals/EqualsEx1.cs
deleted file mode 100644
index 66a01f732b9..00000000000
--- a/snippets/csharp/System/IEquatableT/Equals/EqualsEx1.cs
+++ /dev/null
@@ -1,137 +0,0 @@
-//
-using System;
-using System.Collections.Generic;
-using System.Text.RegularExpressions;
-
-public class Person : IEquatable
-{
- private string uniqueSsn;
- private string lName;
-
- public Person(string lastName, string ssn)
- {
- this.SSN = ssn;
- this.LastName = lastName;
- }
-
- public string SSN
- {
- get { return this.uniqueSsn; }
- set {
- if (Regex.IsMatch(value, @"\d{9}"))
- uniqueSsn = String.Format("{0}-(1}-{2}", value.Substring(0, 3),
- value.Substring(3, 2),
- value.Substring(5, 4));
- else if (Regex.IsMatch(value, @"\d{3}-\d{2}-\d{4}"))
- uniqueSsn = value;
- else
- throw new FormatException("The social security number has an invalid format.");
- }
- }
-
- public string LastName
- {
- get { return this.lName; }
- set {
- if (String.IsNullOrEmpty(value))
- throw new ArgumentException("The last name cannot be null or empty.");
- else
- this.lName = value;
- }
- }
-
- public bool Equals(Person other)
- {
- if (other == null)
- return false;
-
- if (this.uniqueSsn == other.uniqueSsn)
- return true;
- else
- return false;
- }
-
- public override bool Equals(Object obj)
- {
- if (obj == null)
- return false;
-
- Person personObj = obj as Person;
- if (personObj == null)
- return false;
- else
- return Equals(personObj);
- }
-
- public override int GetHashCode()
- {
- return this.SSN.GetHashCode();
- }
-
- public static bool operator == (Person person1, Person person2)
- {
- if (((object)person1) == null || ((object)person2) == null)
- return Object.Equals(person1, person2);
-
- return person1.Equals(person2);
- }
-
- public static bool operator != (Person person1, Person person2)
- {
- if (((object)person1) == null || ((object)person2) == null)
- return ! Object.Equals(person1, person2);
-
- return ! (person1.Equals(person2));
- }
-}
-//
-
-// Snippet2>
-public class TestIEquatable
-{
- public static void Main()
- {
- // Create a Person object for each job applicant.
- Person applicant1 = new Person("Jones", "099-29-4999");
- Person applicant2 = new Person("Jones", "199-29-3999");
- Person applicant3 = new Person("Jones", "299-49-6999");
-
- // Add applicants to a List object.
- List applicants = new List();
- applicants.Add(applicant1);
- applicants.Add(applicant2);
- applicants.Add(applicant3);
-
- // Create a Person object for the final candidate.
- Person candidate = new Person("Jones", "199-29-3999");
- if (applicants.Contains(candidate))
- Console.WriteLine("Found {0} (SSN {1}).",
- candidate.LastName, candidate.SSN);
- else
- Console.WriteLine("Applicant {0} not found.", candidate.SSN);
-
- // Call the shared inherited Equals(Object, Object) method.
- // It will in turn call the IEquatable(Of T).Equals implementation.
- Console.WriteLine("{0}({1}) already on file: {2}.",
- applicant2.LastName,
- applicant2.SSN,
- Person.Equals(applicant2, candidate));
- }
-}
-// The example displays the following output:
-// Found Jones (SSN 199-29-3999).
-// Jones(199-29-3999) already on file: True.
-//
-
-// This tests the handling of null values, but does not appear in the documentation.
-//
-//public class Example
-//{
-// public static void Main()
-// {
-// var p1 = new Person("Joe", "613-24-0068");
-// Person p2 = null;
-//
-// Console.WriteLine(p1 == p2);
-// }
-//}
diff --git a/snippets/csharp/System/IEquatableT/Equals/EqualsEx2.cs b/snippets/csharp/System/IEquatableT/Equals/EqualsEx2.cs
deleted file mode 100644
index b7e12b95342..00000000000
--- a/snippets/csharp/System/IEquatableT/Equals/EqualsEx2.cs
+++ /dev/null
@@ -1,131 +0,0 @@
-//
-using System;
-using System.Collections.Generic;
-using System.Text.RegularExpressions;
-
-public class Person : IEquatable
-{
- private string uniqueSsn;
- private string lName;
-
- public Person(string lastName, string ssn)
- {
- if (Regex.IsMatch(ssn, @"\d{9}"))
- uniqueSsn = $"{ssn.Substring(0, 3)}-{ssn.Substring(3, 2)}-{ssn.Substring(5, 4)}";
- else if (Regex.IsMatch(ssn, @"\d{3}-\d{2}-\d{4}"))
- uniqueSsn = ssn;
- else
- throw new FormatException("The social security number has an invalid format.");
-
- this.LastName = lastName;
- }
-
- public string SSN
- {
- get { return this.uniqueSsn; }
- }
-
- public string LastName
- {
- get { return this.lName; }
- set {
- if (String.IsNullOrEmpty(value))
- throw new ArgumentException("The last name cannot be null or empty.");
- else
- this.lName = value;
- }
- }
-
- public bool Equals(Person other)
- {
- if (other == null)
- return false;
-
- if (this.uniqueSsn == other.uniqueSsn)
- return true;
- else
- return false;
- }
-
- public override bool Equals(Object obj)
- {
- if (obj == null)
- return false;
-
- Person personObj = obj as Person;
- if (personObj == null)
- return false;
- else
- return Equals(personObj);
- }
-
- public override int GetHashCode()
- {
- return this.SSN.GetHashCode();
- }
-
- public static bool operator == (Person person1, Person person2)
- {
- if (((object)person1) == null || ((object)person2) == null)
- return Object.Equals(person1, person2);
-
- return person1.Equals(person2);
- }
-
- public static bool operator != (Person person1, Person person2)
- {
- if (((object)person1) == null || ((object)person2) == null)
- return ! Object.Equals(person1, person2);
-
- return ! (person1.Equals(person2));
- }
-}
-//
-
-public class TestIEquatable
-{
- public static void Main()
- {
- // Create a Person object for each job applicant.
- Person applicant1 = new Person("Jones", "099-29-4999");
- Person applicant2 = new Person("Jones", "199-29-3999");
- Person applicant3 = new Person("Jones", "299-49-6999");
-
- // Add applicants to a List object.
- List applicants = new List();
- applicants.Add(applicant1);
- applicants.Add(applicant2);
- applicants.Add(applicant3);
-
- // Create a Person object for the final candidate.
- Person candidate = new Person("Jones", "199-29-3999");
- if (applicants.Contains(candidate))
- Console.WriteLine("Found {0} (SSN {1}).",
- candidate.LastName, candidate.SSN);
- else
- Console.WriteLine("Applicant {0} not found.", candidate.SSN);
-
- // Call the shared inherited Equals(Object, Object) method.
- // It will in turn call the IEquatable(Of T).Equals implementation.
- Console.WriteLine("{0}({1}) already on file: {2}.",
- applicant2.LastName,
- applicant2.SSN,
- Person.Equals(applicant2, candidate));
- }
-}
-// The example displays the following output:
-// Found Jones (SSN 199-29-3999).
-// Jones(199-29-3999) already on file: True.
-
-// This tests the handling of null values, but does not appear in the documentation.
-//
-//public class Example
-//{
-// public static void Main()
-// {
-// var p1 = new Person("Joe", "613-24-0068");
-// Person p2 = null;
-//
-// Console.WriteLine(p1 == p2);
-// }
-//}
diff --git a/snippets/csharp/System/IEquatableT/Equals/EqualsExample.cs b/snippets/csharp/System/IEquatableT/Equals/EqualsExample.cs
new file mode 100644
index 00000000000..e5e6a43bac0
--- /dev/null
+++ b/snippets/csharp/System/IEquatableT/Equals/EqualsExample.cs
@@ -0,0 +1,56 @@
+//
+List applicants = new List()
+{
+ new Person("Jones", "099-29-4999"),
+ new Person("Jones", "199-29-3999"),
+ new Person("Jones", "299-49-6999")
+};
+
+// Create a Person object for the final candidate.
+Person candidate = new Person("Jones", "199-29-3999");
+bool contains = applicants.Contains(candidate);
+Console.WriteLine($"{candidate.LastName} ({candidate.NationalId}) is on record: {contains}");
+// The example prints the following output:
+// Jones (199-29-3999) is on record: True
+//
+
+//
+public class Person : IEquatable
+{
+ public Person(string lastName, string ssn)
+ {
+ LastName = lastName;
+ NationalId = ssn;
+ }
+
+ public string LastName { get; }
+
+ public string NationalId { get; }
+
+ public bool Equals(Person? other) => other is not null && other.NationalId == NationalId;
+
+ public override bool Equals(object? obj) => Equals(obj as Person);
+
+ public override int GetHashCode() => NationalId.GetHashCode();
+
+ public static bool operator ==(Person person1, Person person2)
+ {
+ if (person1 is null)
+ {
+ return person2 is null;
+ }
+
+ return person1.Equals(person2);
+ }
+
+ public static bool operator !=(Person person1, Person person2)
+ {
+ if (person1 is null)
+ {
+ return person2 is not null;
+ }
+
+ return !person1.Equals(person2);
+ }
+}
+//
diff --git a/snippets/csharp/System/IEquatableT/Equals/Snippet12.cs b/snippets/csharp/System/IEquatableT/Equals/Snippet12.cs
deleted file mode 100644
index cfb5e526740..00000000000
--- a/snippets/csharp/System/IEquatableT/Equals/Snippet12.cs
+++ /dev/null
@@ -1,135 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text.RegularExpressions;
-
-public class Person : IEquatable
-{
- private string uniqueSsn;
- private string lName;
-
- public Person(string lastName, string ssn)
- {
- this.SSN = ssn;
- this.LastName = lastName;
- }
-
- public string SSN
- {
- get { return this.uniqueSsn; }
- set {
- if (Regex.IsMatch(value, @"\d{9}"))
- uniqueSsn = String.Format("{0}-(1}-{2}", value.Substring(0, 3),
- value.Substring(3, 2),
- value.Substring(5, 4));
- else if (Regex.IsMatch(value, @"\d{3}-\d{2}-\d{4}"))
- uniqueSsn = value;
- else
- throw new FormatException("The social security number has an invalid format.");
- }
- }
-
- public string LastName
- {
- get { return this.lName; }
- set {
- if (String.IsNullOrEmpty(value))
- throw new ArgumentException("The last name cannot be null or empty.");
- else
- this.lName = value;
- }
- }
-
- public bool Equals(Person other)
- {
- if (other == null)
- return false;
-
- if (this.uniqueSsn == other.uniqueSsn)
- return true;
- else
- return false;
- }
-
- public override bool Equals(Object obj)
- {
- if (obj == null)
- return false;
-
- Person personObj = obj as Person;
- if (personObj == null)
- return false;
- else
- return Equals(personObj);
- }
-
- public override int GetHashCode()
- {
- return this.SSN.GetHashCode();
- }
-
- public static bool operator == (Person person1, Person person2)
- {
- if (((object)person1) == null || ((object)person2) == null)
- return Object.Equals(person1, person2);
-
- return person1.Equals(person2);
- }
-
- public static bool operator != (Person person1, Person person2)
- {
- if (((object)person1) == null || ((object)person2) == null)
- return ! Object.Equals(person1, person2);
-
- return ! (person1.Equals(person2));
- }
-}
-
-//
-public class TestIEquatable
-{
- public static void Main()
- {
- // Create a Person object for each job applicant.
- Person applicant1 = new Person("Jones", "099-29-4999");
- Person applicant2 = new Person("Jones", "199-29-3999");
- Person applicant3 = new Person("Jones", "299-49-6999");
-
- // Add applicants to a List object.
- List applicants = new List();
- applicants.Add(applicant1);
- applicants.Add(applicant2);
- applicants.Add(applicant3);
-
- // Create a Person object for the final candidate.
- Person candidate = new Person("Jones", "199-29-3999");
- if (applicants.Contains(candidate))
- Console.WriteLine("Found {0} (SSN {1}).",
- candidate.LastName, candidate.SSN);
- else
- Console.WriteLine("Applicant {0} not found.", candidate.SSN);
-
- // Call the shared inherited Equals(Object, Object) method.
- // It will in turn call the IEquatable(Of T).Equals implementation.
- Console.WriteLine("{0}({1}) already on file: {2}.",
- applicant2.LastName,
- applicant2.SSN,
- Person.Equals(applicant2, candidate));
- }
-}
-// The example displays the following output:
-// Found Jones (SSN 199-29-3999).
-// Jones(199-29-3999) already on file: True.
-//
-
-// This tests the handling of null values, but does not appear in the documentation.
-//
-//public class Example
-//{
-// public static void Main()
-// {
-// var p1 = new Person("Joe", "613-24-0068");
-// Person p2 = null;
-//
-// Console.WriteLine(p1 == p2);
-// }
-//}
diff --git a/snippets/csharp/System/ThreadStaticAttribute/Overview/Project.csproj b/snippets/csharp/System/ThreadStaticAttribute/Overview/Project.csproj
index aa9fd2ecaaf..d260053fe00 100644
--- a/snippets/csharp/System/ThreadStaticAttribute/Overview/Project.csproj
+++ b/snippets/csharp/System/ThreadStaticAttribute/Overview/Project.csproj
@@ -3,6 +3,7 @@
Exe
net6.0
+ enable
-
+
\ No newline at end of file
diff --git a/snippets/csharp/System/ThreadStaticAttribute/Overview/threadsafe2a.cs b/snippets/csharp/System/ThreadStaticAttribute/Overview/threadsafe2a.cs
index 9e42b59c289..fcc8fd8c3d2 100644
--- a/snippets/csharp/System/ThreadStaticAttribute/Overview/threadsafe2a.cs
+++ b/snippets/csharp/System/ThreadStaticAttribute/Overview/threadsafe2a.cs
@@ -2,108 +2,43 @@
using System;
using System.Threading;
-public class Example
+class Program
{
- [ThreadStatic] static double previous = 0.0;
- [ThreadStatic] static double sum = 0.0;
- [ThreadStatic] static int calls = 0;
- [ThreadStatic] static bool abnormal;
- static int totalNumbers = 0;
- static CountdownEvent countdown;
- private static Object lockObj;
- Random rand;
-
- public Example()
- {
- rand = new Random();
- lockObj = new Object();
- countdown = new CountdownEvent(1);
- }
+ [ThreadStatic]
+ private static string? _requestId;
- public static void Main()
- {
- Example ex = new Example();
- Thread.CurrentThread.Name = "Main";
- ex.Execute();
- countdown.Wait();
- Console.WriteLine("{0:N0} random numbers were generated.", totalNumbers);
- }
+ static void Main()
+ {
+ Thread thread1 = new(ProcessRequest);
+ Thread thread2 = new(ProcessRequest);
- private void Execute()
- {
- for (int threads = 1; threads <= 10; threads++)
- {
- Thread newThread = new Thread(new ThreadStart(this.GetRandomNumbers));
- countdown.AddCount();
- newThread.Name = threads.ToString();
- newThread.Start();
- }
- this.GetRandomNumbers();
- }
+ thread1.Start("REQ-001");
+ thread2.Start("REQ-002");
- private void GetRandomNumbers()
- {
- double result = 0.0;
+ thread1.Join();
+ thread2.Join();
- for (int ctr = 0; ctr < 2000000; ctr++)
- {
- lock (lockObj) {
- result = rand.NextDouble();
- calls++;
- Interlocked.Increment(ref totalNumbers);
- // We should never get the same random number twice.
- if (result == previous) {
- abnormal = true;
- break;
- }
- else {
- previous = result;
- sum += result;
- }
- }
- }
- // get last result
- if (abnormal)
- Console.WriteLine("Result is {0} in {1}", previous, Thread.CurrentThread.Name);
-
- Console.WriteLine("Thread {0} finished random number generation.", Thread.CurrentThread.Name);
- Console.WriteLine("Sum = {0:N4}, Mean = {1:N4}, n = {2:N0}\n", sum, sum/calls, calls);
- countdown.Signal();
- }
+ Console.WriteLine("Main thread execution completed.");
+ }
+
+ static void ProcessRequest(object? requestId)
+ {
+ // Assign the request ID to the thread-static field
+ _requestId = requestId as string;
+
+ // Simulate request processing across multiple method calls
+ PerformDatabaseOperation();
+ PerformLogging();
+ }
+
+ static void PerformDatabaseOperation()
+ {
+ Console.WriteLine($"Thread {Environment.CurrentManagedThreadId}: Processing DB operation for request {_requestId}");
+ }
+
+ static void PerformLogging()
+ {
+ Console.WriteLine($"Thread {Environment.CurrentManagedThreadId}: Logging request {_requestId}");
+ }
}
-// The example displays output similar to the following:
-// Thread 1 finished random number generation.
-// Sum = 1,000,556.7483, Mean = 0.5003, n = 2,000,000
-//
-// Thread 6 finished random number generation.
-// Sum = 999,704.3865, Mean = 0.4999, n = 2,000,000
-//
-// Thread 2 finished random number generation.
-// Sum = 999,680.8904, Mean = 0.4998, n = 2,000,000
-//
-// Thread 10 finished random number generation.
-// Sum = 999,437.5132, Mean = 0.4997, n = 2,000,000
-//
-// Thread 8 finished random number generation.
-// Sum = 1,000,663.7789, Mean = 0.5003, n = 2,000,000
-//
-// Thread 4 finished random number generation.
-// Sum = 999,379.5978, Mean = 0.4997, n = 2,000,000
-//
-// Thread 5 finished random number generation.
-// Sum = 1,000,011.0605, Mean = 0.5000, n = 2,000,000
-//
-// Thread 9 finished random number generation.
-// Sum = 1,000,637.4556, Mean = 0.5003, n = 2,000,000
-//
-// Thread Main finished random number generation.
-// Sum = 1,000,676.2381, Mean = 0.5003, n = 2,000,000
-//
-// Thread 3 finished random number generation.
-// Sum = 999,951.1025, Mean = 0.5000, n = 2,000,000
-//
-// Thread 7 finished random number generation.
-// Sum = 1,000,844.5217, Mean = 0.5004, n = 2,000,000
-//
-// 22,000,000 random numbers were generated.
//
diff --git a/snippets/fsharp/System/IEquatableT/Equals/Equals.fsproj b/snippets/fsharp/System/IEquatableT/Equals/Equals.fsproj
new file mode 100644
index 00000000000..32c2318f221
--- /dev/null
+++ b/snippets/fsharp/System/IEquatableT/Equals/Equals.fsproj
@@ -0,0 +1,12 @@
+
+
+
+ Exe
+ net8.0
+
+
+
+
+
+
+
diff --git a/snippets/fsharp/System/IEquatableT/Equals/EqualsEx2.fs b/snippets/fsharp/System/IEquatableT/Equals/EqualsEx2.fs
deleted file mode 100644
index 29e42d75a6a..00000000000
--- a/snippets/fsharp/System/IEquatableT/Equals/EqualsEx2.fs
+++ /dev/null
@@ -1,93 +0,0 @@
-module EqualsEx2
-
-//
-open System
-open System.Text.RegularExpressions
-
-type Person(lastName, ssn) =
- let mutable lastName = lastName
- let ssn =
- if Regex.IsMatch(ssn, @"\d{9}") then
- $"{ssn.Substring(0, 3)}-{ssn.Substring(3, 2)}-{ssn.Substring(5, 4)}"
- elif Regex.IsMatch(ssn, @"\d{3}-\d{2}-\d{4}") then
- ssn
- else
- raise (FormatException "The social security number has an invalid format.")
-
- member _.SSN =
- ssn
-
- member _.LastName
- with get () = lastName
- and set (value) =
- if String.IsNullOrEmpty value then
- invalidArg (nameof value) "The last name cannot be null or empty."
- else
- lastName <- value
-
- static member op_Equality (person1: Person, person2: Person) =
- if box person1 |> isNull || box person2 |> isNull then
- Object.Equals(person1, person2)
- else
- person1.Equals person2
-
- static member op_Inequality (person1: Person, person2: Person) =
- if box person1 |> isNull || box person2 |> isNull then
- Object.Equals(person1, person2) |> not
- else
- person1.Equals person2 |> not
-
- override _.GetHashCode() =
- ssn.GetHashCode()
-
- override this.Equals(obj: obj) =
- match obj with
- | :? Person as personObj ->
- (this :> IEquatable<_>).Equals personObj
- | _ -> false
-
- interface IEquatable with
- member this.Equals(other: Person) =
- match box other with
- | null -> false
- | _ ->
- this.SSN = other.SSN
-//
-// Create a Person object for each job applicant.
-let applicant1 = Person("Jones", "099-29-4999")
-let applicant2 = Person("Jones", "199-29-3999")
-let applicant3 = Person("Jones", "299-49-6999")
-
-// Add applicants to a List object.
-let applicants = ResizeArray()
-applicants.Add applicant1
-applicants.Add applicant2
-applicants.Add applicant3
-
-// Create a Person object for the final candidate.
-let candidate = Person("Jones", "199-29-3999")
-if applicants.Contains candidate then
- printfn $"Found {candidate.LastName} (SSN {candidate.SSN})."
-else
- printfn $"Applicant {candidate.SSN} not found."
-
-// Call the shared inherited Equals(Object, Object) method.
-// It will in turn call the IEquatable.Equals implementation.
-printfn $"{applicant2.LastName}({applicant2.SSN}) already on file: {Person.Equals(applicant2, candidate)}."
-
-// The example displays the following output:
-// Found Jones (SSN 199-29-3999).
-// Jones(199-29-3999) already on file: True.
-
-// This tests the handling of null values, but does not appear in the documentation.
-//
-//public class Example
-//{
-// public static void Main()
-// {
-// var p1 = new Person("Joe", "613-24-0068")
-// Person p2 = null
-//
-// Console.WriteLine(p1 == p2)
-// }
-//}
\ No newline at end of file
diff --git a/snippets/fsharp/System/IEquatableT/Equals/EqualsExample.fs b/snippets/fsharp/System/IEquatableT/Equals/EqualsExample.fs
new file mode 100644
index 00000000000..9aff81cdf57
--- /dev/null
+++ b/snippets/fsharp/System/IEquatableT/Equals/EqualsExample.fs
@@ -0,0 +1,39 @@
+
+//
+open System
+
+type Person(lastName: string, nationalId: string) =
+ member this.LastName = lastName
+ member this.NationalId = nationalId
+
+ interface IEquatable with
+ member this.Equals(other: Person) =
+ other.NationalId = this.NationalId
+
+ override this.Equals(obj: obj) =
+ match obj with
+ | :? Person as person -> (this :> IEquatable).Equals(person)
+ | _ -> false
+
+ override this.GetHashCode() =
+ this.NationalId.GetHashCode()
+
+ static member (==) (person1: Person, person2: Person) =
+ person1.Equals(person2)
+
+ static member (!=) (person1: Person, person2: Person) =
+ not (person1.Equals(person2))
+//
+
+//
+let applicants =
+ [ Person("Jones", "099-29-4999")
+ Person("Jones", "199-29-3999")
+ Person("Jones", "299-49-6999") ]
+
+let candidate = Person("Jones", "199-29-3999")
+let contains = List.contains candidate applicants
+printfn "%s (%s) is on record: %b" candidate.LastName candidate.NationalId contains
+// The example prints the following output:
+// Jones (199-29-3999) is on record: true
+//
diff --git a/snippets/fsharp/System/IEquatableT/Equals/Snippet12.fs b/snippets/fsharp/System/IEquatableT/Equals/Snippet12.fs
deleted file mode 100644
index 39e48b695c9..00000000000
--- a/snippets/fsharp/System/IEquatableT/Equals/Snippet12.fs
+++ /dev/null
@@ -1,80 +0,0 @@
-open System
-open System.Collections.Generic
-open System.Text.RegularExpressions
-
-type Person(lastName, ssn) =
- let mutable lastName = lastName
- let ssn =
- if Regex.IsMatch(ssn, @"\d{9}") then
- $"{ssn.Substring(0, 3)}-{ssn.Substring(3, 2)}-{ssn.Substring(5, 4)}"
- elif Regex.IsMatch(ssn, @"\d{3}-\d{2}-\d{4}") then
- ssn
- else
- raise (FormatException "The social security number has an invalid format.")
-
- member _.SSN =
- ssn
-
- member _.LastName
- with get () = lastName
- and set (value) =
- if String.IsNullOrEmpty value then
- invalidArg (nameof value) "The last name cannot be null or empty."
- else
- lastName <- value
-
- static member op_Equality (person1: Person, person2: Person) =
- if box person1 |> isNull || box person2 |> isNull then
- Object.Equals(person1, person2)
- else
- person1.Equals person2
-
- static member op_Inequality (person1: Person, person2: Person) =
- if box person1 |> isNull || box person2 |> isNull then
- Object.Equals(person1, person2) |> not
- else
- person1.Equals person2 |> not
-
- override _.GetHashCode() =
- ssn.GetHashCode()
-
- override this.Equals(obj: obj) =
- match obj with
- | :? Person as personObj ->
- (this :> IEquatable<_>).Equals personObj
- | _ -> false
-
- interface IEquatable with
- member this.Equals(other: Person) =
- match box other with
- | null -> false
- | _ ->
- this.SSN = other.SSN
-
-//
-// Create a Person object for each job applicant.
-let applicant1 = Person("Jones", "099-29-4999")
-let applicant2 = Person("Jones", "199-29-3999")
-let applicant3 = Person("Jones", "299-49-6999")
-
-// Add applicants to a List object.
-let applicants = ResizeArray()
-applicants.Add applicant1
-applicants.Add applicant2
-applicants.Add applicant3
-
-// Create a Person object for the final candidate.
-let candidate = Person("Jones", "199-29-3999")
-if applicants.Contains candidate then
- printfn $"Found {candidate.LastName} (SSN {candidate.SSN})."
-else
- printfn $"Applicant {candidate.SSN} not found."
-
-// Call the shared inherited Equals(Object, Object) method.
-// It will in turn call the IEquatable.Equals implementation.
-printfn $"{applicant2.LastName}({applicant2.SSN}) already on file: {Person.Equals(applicant2, candidate)}."
-
-// The example displays the following output:
-// Found Jones (SSN 199-29-3999).
-// Jones(199-29-3999) already on file: True.
-//
\ No newline at end of file
diff --git a/snippets/fsharp/System/ThreadStaticAttribute/Overview/threadsafe2a.fs b/snippets/fsharp/System/ThreadStaticAttribute/Overview/threadsafe2a.fs
index d2d1aec32ef..6e76d8a93f1 100644
--- a/snippets/fsharp/System/ThreadStaticAttribute/Overview/threadsafe2a.fs
+++ b/snippets/fsharp/System/ThreadStaticAttribute/Overview/threadsafe2a.fs
@@ -2,95 +2,31 @@
open System
open System.Threading
-type Example() =
- []
- static val mutable private previous : double
+type ThreadLocal() =
+ []
+ static val mutable private requestId: string option
- []
- static val mutable private sum : double
-
- []
- static val mutable private calls : int
+ static member PerformLogging() =
+ Console.WriteLine($"Thread {Environment.CurrentManagedThreadId}: Logging request {ThreadLocal.requestId.Value}")
- []
- static val mutable private abnormal : bool
-
- static let mutable totalNumbers = 0
- static let countdown = new CountdownEvent(1)
- static let lockObj = obj ()
- let rand = Random()
+ static member PerformDatabaseOperation() =
+ Console.WriteLine($"Thread {Environment.CurrentManagedThreadId}: Processing DB operation for request {ThreadLocal.requestId.Value}")
+ static member ProcessRequest(reqId: obj) =
+ ThreadLocal.requestId <- Some(reqId :?> string)
+ ThreadLocal.PerformDatabaseOperation()
+ ThreadLocal.PerformLogging()
- member this.Execute() =
- for threads = 1 to 10 do
- let newThread = new Thread(ThreadStart this.GetRandomNumbers)
- countdown.AddCount()
- newThread.Name <- threads.ToString()
- newThread.Start()
- this.GetRandomNumbers()
- countdown.Wait()
- printfn $"{totalNumbers:N0} random numbers were generated."
+[]
+let main _ =
+ let thread1 = Thread(ThreadStart(fun () -> ThreadLocal.ProcessRequest("REQ-001")))
+ let thread2 = Thread(ThreadStart(fun () -> ThreadLocal.ProcessRequest("REQ-002")))
- member _.GetRandomNumbers() =
- let mutable i = 0
- while i < 2000000 do
- lock lockObj (fun () ->
- let result = rand.NextDouble()
- Example.calls <- Example.calls + 1
- Interlocked.Increment &totalNumbers |> ignore
- // We should never get the same random number twice.
- if result = Example.previous then
- Example.abnormal <- true
- i <- 2000001 // break
- else
- Example.previous <- result
- Example.sum <- Example.sum + result )
- i <- i + 1
- // get last result
- if Example.abnormal then
- printfn $"Result is {Example.previous} in {Thread.CurrentThread.Name}"
-
- printfn $"Thread {Thread.CurrentThread.Name} finished random number generation."
- printfn $"Sum = {Example.sum:N4}, Mean = {Example.sum / float Example.calls:N4}, n = {Example.calls:N0}\n"
- countdown.Signal() |> ignore
+ thread1.Start()
+ thread2.Start()
+ thread1.Join()
+ thread2.Join()
-let ex = Example()
-Thread.CurrentThread.Name <- "Main"
-ex.Execute()
-
-// The example displays output similar to the following:
-// Thread 1 finished random number generation.
-// Sum = 1,000,556.7483, Mean = 0.5003, n = 2,000,000
-//
-// Thread 6 finished random number generation.
-// Sum = 999,704.3865, Mean = 0.4999, n = 2,000,000
-//
-// Thread 2 finished random number generation.
-// Sum = 999,680.8904, Mean = 0.4998, n = 2,000,000
-//
-// Thread 10 finished random number generation.
-// Sum = 999,437.5132, Mean = 0.4997, n = 2,000,000
-//
-// Thread 8 finished random number generation.
-// Sum = 1,000,663.7789, Mean = 0.5003, n = 2,000,000
-//
-// Thread 4 finished random number generation.
-// Sum = 999,379.5978, Mean = 0.4997, n = 2,000,000
-//
-// Thread 5 finished random number generation.
-// Sum = 1,000,011.0605, Mean = 0.5000, n = 2,000,000
-//
-// Thread 9 finished random number generation.
-// Sum = 1,000,637.4556, Mean = 0.5003, n = 2,000,000
-//
-// Thread Main finished random number generation.
-// Sum = 1,000,676.2381, Mean = 0.5003, n = 2,000,000
-//
-// Thread 3 finished random number generation.
-// Sum = 999,951.1025, Mean = 0.5000, n = 2,000,000
-//
-// Thread 7 finished random number generation.
-// Sum = 1,000,844.5217, Mean = 0.5004, n = 2,000,000
-//
-// 22,000,000 random numbers were generated.
+ Console.WriteLine("Main thread execution completed.")
+ 0
//
\ No newline at end of file
diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/Equals.vbproj b/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/Equals.vbproj
new file mode 100644
index 00000000000..4855707fd9d
--- /dev/null
+++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/Equals.vbproj
@@ -0,0 +1,9 @@
+
+
+
+ Exe
+ vb
+ net8.0
+
+
+
diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsEx2.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsEx2.vb
deleted file mode 100644
index 425406deef9..00000000000
--- a/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsEx2.vb
+++ /dev/null
@@ -1,120 +0,0 @@
-' Visual Basic .NET Document
-Option Strict On
-
-'
-Imports System.Collections.Generic
-Imports System.Text.RegularExpressions
-
-Public Class Person : Implements IEquatable(Of Person)
- Private uniqueSsn As String
- Private lName As String
-
- Public Sub New(lastName As String, ssn As String)
- If Regex.IsMatch(ssn, "\d{9}") Then
- uniqueSsn = $"{ssn.Substring(0, 3)}-{ssn.Substring(3, 2)}-{ssn.Substring(5, 4)}"
- ElseIf Regex.IsMatch(ssn, "\d{3}-\d{2}-\d{4}") Then
- uniqueSsn = ssn
- Else
- Throw New FormatException("The social security number has an invalid format.")
- End If
- Me.LastName = lastName
- End Sub
-
- Public ReadOnly Property SSN As String
- Get
- Return Me.uniqueSsn
- End Get
- End Property
-
- Public Property LastName As String
- Get
- Return Me.lName
- End Get
- Set
- If String.IsNullOrEmpty(value) Then
- Throw New ArgumentException("The last name cannot be null or empty.")
- Else
- lname = value
- End If
- End Set
- End Property
-
- Public Overloads Function Equals(other As Person) As Boolean _
- Implements IEquatable(Of Person).Equals
- If other Is Nothing Then Return False
-
- If Me.uniqueSsn = other.uniqueSsn Then
- Return True
- Else
- Return False
- End If
- End Function
-
- Public Overrides Function Equals(obj As Object) As Boolean
- If obj Is Nothing Then Return False
-
- Dim personObj As Person = TryCast(obj, Person)
- If personObj Is Nothing Then
- Return False
- Else
- Return Equals(personObj)
- End If
- End Function
-
- Public Overrides Function GetHashCode() As Integer
- Return Me.SSN.GetHashCode()
- End Function
-
- Public Shared Operator = (person1 As Person, person2 As Person) As Boolean
- If person1 Is Nothing OrElse person2 Is Nothing Then
- Return Object.Equals(person1, person2)
- End If
-
- Return person1.Equals(person2)
- End Operator
-
- Public Shared Operator <> (person1 As Person, person2 As Person) As Boolean
- If person1 Is Nothing OrElse person2 Is Nothing Then
- Return Not Object.Equals(person1, person2)
- End If
-
- Return Not person1.Equals(person2)
- End Operator
-End Class
-'
-
-Module TestIEquatable
- Public Sub Main()
- ' Create a Person object for each job applicant.
- Dim applicant1 As New Person("Jones", "099-29-4999")
- Dim applicant2 As New Person("Jones", "199-29-3999")
- Dim applicant3 As New Person("Jones", "299-49-6999")
-
- ' Add applicants to a List object.
- Dim applicants As New List(Of Person)
- applicants.Add(applicant1)
- applicants.Add(applicant2)
- applicants.Add(applicant3)
-
- ' Create a Person object for the final candidate.
- Dim candidate As New Person("Jones", "199-29-3999")
-
- If applicants.Contains(candidate) Then
- Console.WriteLine("Found {0} (SSN {1}).", _
- candidate.LastName, candidate.SSN)
- Else
- Console.WriteLine("Applicant {0} not found.", candidate.SSN)
- End If
-
- ' Call the shared inherited Equals(Object, Object) method.
- ' It will in turn call the IEquatable(Of T).Equals implementation.
- Console.WriteLine("{0}({1}) already on file: {2}.", _
- applicant2.LastName, _
- applicant2.SSN, _
- Person.Equals(applicant2, candidate))
- End Sub
-End Module
-' The example displays the following output:
-' Found Jones (SSN 199-29-3999).
-' Jones(199-29-3999) already on file: True.
-
diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsExample.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsExample.vb
new file mode 100644
index 00000000000..73cb24e18b8
--- /dev/null
+++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsExample.vb
@@ -0,0 +1,61 @@
+' Visual Basic .NET Document
+Option Strict On
+
+'
+Public Class Person
+ Implements IEquatable(Of Person)
+
+ Public Sub New(lastName As String, nationalId As String)
+ Me.LastName = lastName
+ Me.NationalId = nationalId
+ End Sub
+
+ Public ReadOnly Property LastName As String
+ Public ReadOnly Property NationalId As String
+
+ Public Overloads Function Equals(other As Person) As Boolean Implements IEquatable(Of Person).Equals
+ Return other IsNot Nothing AndAlso other.NationalId = Me.NationalId
+ End Function
+
+ Public Overrides Function Equals(obj As Object) As Boolean
+ Return Equals(TryCast(obj, Person))
+ End Function
+
+ Public Overrides Function GetHashCode() As Integer
+ Return NationalId.GetHashCode()
+ End Function
+
+ Public Shared Operator =(person1 As Person, person2 As Person) As Boolean
+ If person1 Is Nothing Then
+ Return person2 Is Nothing
+ End If
+ Return person1.Equals(person2)
+ End Operator
+
+ Public Shared Operator <>(person1 As Person, person2 As Person) As Boolean
+ If person1 Is Nothing Then
+ Return person2 IsNot Nothing
+ End If
+ Return Not person1.Equals(person2)
+ End Operator
+End Class
+'
+
+Module EqualsExample
+ Public Sub Main()
+ '
+ Dim applicants As New List(Of Person)
+ applicants.Add(New Person("Jones", "099-29-4999"))
+ applicants.Add(New Person("Jones", "199-29-3999"))
+ applicants.Add(New Person("Jones", "299-49-6999"))
+
+ ' Create a Person object for the final candidate.
+ Dim candidate As New Person("Jones", "199-29-3999")
+ Dim contains As Boolean = applicants.Contains(candidate)
+ Console.WriteLine($"{candidate.LastName} ({candidate.NationalId}) is on record: {contains}")
+ ' The example prints the following output:
+ ' Jones (199-29-3999) Is on record True
+ '
+ End Sub
+End Module
+
diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/Snippet12.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/Snippet12.vb
deleted file mode 100644
index 6de5888d74a..00000000000
--- a/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/Snippet12.vb
+++ /dev/null
@@ -1,125 +0,0 @@
-' Visual Basic .NET Document
-Option Strict On
-
-Imports System.Collections.Generic
-Imports System.Text.RegularExpressions
-
-Public Class Person : Implements IEquatable(Of Person)
- Private uniqueSsn As String
- Private lName As String
-
- Public Sub New(lastName As String, ssn As String)
- Me.SSN = ssn
- Me.LastName = lastName
- End Sub
-
- Public Property SSN As String
- Set
- If Regex.IsMatch(value, "\d{9}") Then
- uniqueSsn = String.Format("{0}-(1}-{2}", value.Substring(0, 3), _
- value.Substring(3, 2), _
- value.Substring(5, 4))
- ElseIf Regex.IsMatch(value, "\d{3}-\d{2}-\d{4}") Then
- uniqueSsn = value
- Else
- Throw New FormatException("The social security number has an invalid format.")
- End If
- End Set
- Get
- Return Me.uniqueSsn
- End Get
- End Property
-
- Public Property LastName As String
- Get
- Return Me.lName
- End Get
- Set
- If String.IsNullOrEmpty(value) Then
- Throw New ArgumentException("The last name cannot be null or empty.")
- Else
- lname = value
- End If
- End Set
- End Property
-
- Public Overloads Function Equals(other As Person) As Boolean _
- Implements IEquatable(Of Person).Equals
- If other Is Nothing Then Return False
-
- If Me.uniqueSsn = other.uniqueSsn Then
- Return True
- Else
- Return False
- End If
- End Function
-
- Public Overrides Function Equals(obj As Object) As Boolean
- If obj Is Nothing Then Return False
-
- Dim personObj As Person = TryCast(obj, Person)
- If personObj Is Nothing Then
- Return False
- Else
- Return Equals(personObj)
- End If
- End Function
-
- Public Overrides Function GetHashCode() As Integer
- Return Me.SSN.GetHashCode()
- End Function
-
- Public Shared Operator = (person1 As Person, person2 As Person) As Boolean
- If person1 Is Nothing OrElse person2 Is Nothing Then
- Return Object.Equals(person1, person2)
- End If
-
- Return person1.Equals(person2)
- End Operator
-
- Public Shared Operator <> (person1 As Person, person2 As Person) As Boolean
- If person1 Is Nothing OrElse person2 Is Nothing Then
- Return Not Object.Equals(person1, person2)
- End If
-
- Return Not person1.Equals(person2)
- End Operator
-End Class
-
-'
-Module TestIEquatable
- Public Sub Main()
- ' Create a Person object for each job applicant.
- Dim applicant1 As New Person("Jones", "099-29-4999")
- Dim applicant2 As New Person("Jones", "199-29-3999")
- Dim applicant3 As New Person("Jones", "299-49-6999")
-
- ' Add applicants to a List object.
- Dim applicants As New List(Of Person)
- applicants.Add(applicant1)
- applicants.Add(applicant2)
- applicants.Add(applicant3)
-
- ' Create a Person object for the final candidate.
- Dim candidate As New Person("Jones", "199-29-3999")
-
- If applicants.Contains(candidate) Then
- Console.WriteLine("Found {0} (SSN {1}).", _
- candidate.LastName, candidate.SSN)
- Else
- Console.WriteLine("Applicant {0} not found.", candidate.SSN)
- End If
-
- ' Call the shared inherited Equals(Object, Object) method.
- ' It will in turn call the IEquatable(Of T).Equals implementation.
- Console.WriteLine("{0}({1}) already on file: {2}.", _
- applicant2.LastName, _
- applicant2.SSN, _
- Person.Equals(applicant2, candidate))
- End Sub
-End Module
-' The example displays the following output:
-' Found Jones (SSN 199-29-3999).
-' Jones(199-29-3999) already on file: True.
-'
-
diff --git a/snippets/fsharp/System/IEquatableT/Equals/fs.fsproj b/snippets/visualbasic/VS_Snippets_CLR_System/system.threadstaticattribute/vb/Program.vbproj
similarity index 60%
rename from snippets/fsharp/System/IEquatableT/Equals/fs.fsproj
rename to snippets/visualbasic/VS_Snippets_CLR_System/system.threadstaticattribute/vb/Program.vbproj
index 34dea6b9fa0..adbde6e0619 100644
--- a/snippets/fsharp/System/IEquatableT/Equals/fs.fsproj
+++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.threadstaticattribute/vb/Program.vbproj
@@ -1,11 +1,8 @@
+
Exe
net6.0
-
-
-
-
\ No newline at end of file
diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.threadstaticattribute/vb/threadsafe2a.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.threadstaticattribute/vb/threadsafe2a.vb
index 0b8727643b7..0f9fb059358 100644
--- a/snippets/visualbasic/VS_Snippets_CLR_System/system.threadstaticattribute/vb/threadsafe2a.vb
+++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.threadstaticattribute/vb/threadsafe2a.vb
@@ -2,105 +2,43 @@
Option Strict On
'
+Imports System
Imports System.Threading
-Public Class Example
- Shared previous As Double = 0.0
- Shared sum As Double = 0.0
- Shared calls As Integer = 0
- Shared abnormal As Boolean
- Shared totalNumbers As Integer = 0
- Shared countdown As CountdownEvent
- Private Shared lockObj As Object
- Dim rand As Random
+Module Program
- Public Sub New()
- rand = New Random()
- lockObj = New Object()
- countdown = New CountdownEvent(1)
- End Sub
+
+ Private _requestId As String
- Public Shared Sub Main()
- Dim ex As New Example()
- Thread.CurrentThread.Name = "Main"
- ex.Execute()
- countdown.Wait()
- Console.WriteLine("{0:N0} random numbers were generated.", totalNumbers)
- End Sub
+ Sub Main()
+ Dim thread1 As New Thread(AddressOf ProcessRequest)
+ Dim thread2 As New Thread(AddressOf ProcessRequest)
- Private Sub Execute()
- For threads As Integer = 1 To 10
- Dim newThread As New Thread(New ThreadStart(AddressOf GetRandomNumbers))
- countdown.AddCount()
- newThread.Name = threads.ToString()
- newThread.Start()
- Next
- Me.GetRandomNumbers()
- End Sub
+ thread1.Start("REQ-001")
+ thread2.Start("REQ-002")
- Private Sub GetRandomNumbers()
- Dim result As Double = 0.0
-
-
- For ctr As Integer = 1 To 2000000
- SyncLock lockObj
- result = rand.NextDouble()
- calls += 1
- Interlocked.Increment(totalNumbers)
- ' We should never get the same random number twice.
- If result = previous Then
- abnormal = True
- Exit For
- Else
- previous = result
- sum += result
- End If
- End SyncLock
- Next
- ' Get last result.
- If abnormal Then
- Console.WriteLine("Result is {0} in {1}", previous, Thread.CurrentThread.Name)
- End If
-
- Console.WriteLine("Thread {0} finished random number generation.", Thread.CurrentThread.Name)
- Console.WriteLine("Sum = {0:N4}, Mean = {1:N4}, n = {2:N0}", sum, sum/calls, calls)
- Console.WriteLine()
- countdown.Signal()
- End Sub
-End Class
-' The example displays output similar to the following:
-' Thread 1 finished random number generation.
-' Sum = 1,000,556.7483, Mean = 0.5003, n = 2,000,000
-'
-' Thread 6 finished random number generation.
-' Sum = 999,704.3865, Mean = 0.4999, n = 2,000,000
-'
-' Thread 2 finished random number generation.
-' Sum = 999,680.8904, Mean = 0.4998, n = 2,000,000
-'
-' Thread 10 finished random number generation.
-' Sum = 999,437.5132, Mean = 0.4997, n = 2,000,000
-'
-' Thread 8 finished random number generation.
-' Sum = 1,000,663.7789, Mean = 0.5003, n = 2,000,000
-'
-' Thread 4 finished random number generation.
-' Sum = 999,379.5978, Mean = 0.4997, n = 2,000,000
-'
-' Thread 5 finished random number generation.
-' Sum = 1,000,011.0605, Mean = 0.5000, n = 2,000,000
-'
-' Thread 9 finished random number generation.
-' Sum = 1,000,637.4556, Mean = 0.5003, n = 2,000,000
-'
-' Thread Main finished random number generation.
-' Sum = 1,000,676.2381, Mean = 0.5003, n = 2,000,000
-'
-' Thread 3 finished random number generation.
-' Sum = 999,951.1025, Mean = 0.5000, n = 2,000,000
-'
-' Thread 7 finished random number generation.
-' Sum = 1,000,844.5217, Mean = 0.5004, n = 2,000,000
-'
-' 22,000,000 random numbers were generated.
+ thread1.Join()
+ thread2.Join()
+
+ Console.WriteLine("Main thread execution completed.")
+ End Sub
+
+ Sub ProcessRequest(ByVal requestId As Object)
+ ' Assign the request ID to the thread-static field
+ _requestId = requestId.ToString()
+
+ ' Simulate request processing across multiple method calls
+ PerformDatabaseOperation()
+ PerformLogging()
+ End Sub
+
+ Sub PerformDatabaseOperation()
+ Console.WriteLine($"Thread {Environment.CurrentManagedThreadId}: Processing DB operation for request {_requestId}")
+ End Sub
+
+ Sub PerformLogging()
+ Console.WriteLine($"Thread {Environment.CurrentManagedThreadId}: Logging request {_requestId}")
+ End Sub
+
+End Module
'
diff --git a/xml/System/IEquatable`1.xml b/xml/System/IEquatable`1.xml
index b30e47c72cc..47967e257e3 100644
--- a/xml/System/IEquatable`1.xml
+++ b/xml/System/IEquatable`1.xml
@@ -60,11 +60,16 @@
> The interface defines the method, which determines the sort order of instances of the implementing type. The interface defines the method, which determines the equality of instances of the implementing type.
The interface is used by generic collection objects such as , , and when testing for equality in such methods as `Contains`, `IndexOf`, `LastIndexOf`, and `Remove`. It should be implemented for any object that might be stored in a generic collection.
-
-
-
+
+For more information about implementing the interface, see remarks on the method.
+
## Examples
- See the example for the method.
+ The following example shows the partial implementation of a `Person` class that implements and has two properties, `LastName` and `NationalId`. `NationalId` is considered to be a unique identifier, therefore the method returns `True` if the `NationalId` property of two `Person` objects is identical; otherwise, it returns `False`.
+ (Note that the F# example does not handle `null` values for `Person` instances.)
+
+ :::code language="csharp" source="~/snippets/csharp/System/IEquatableT/Equals/EqualsExample.cs" id="Person":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/IEquatableT/Equals/EqualsExample.fs" id="Person":::
+ :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsExample.vb" id="Person":::
]]>
@@ -163,17 +168,18 @@
## Examples
- The following example shows the partial implementation of a `Person` class that implements and has two properties, `LastName` and `SSN`. The method returns `True` if the `SSN` property of two `Person` objects is identical; otherwise, it returns `False`.
+ The following example shows the partial implementation of a `Person` class that implements and has two properties, `LastName` and `NationalId`. `NationalId` is considered to be a unique identifier, therefore the method returns `True` if the `NationalId` property of two `Person` objects is identical; otherwise, it returns `False`.
+ (Note that the F# example does not handle `null` values for `Person` instances.)
- :::code language="csharp" source="~/snippets/csharp/System/IEquatableT/Equals/EqualsEx2.cs" id="Snippet3":::
- :::code language="fsharp" source="~/snippets/fsharp/System/IEquatableT/Equals/EqualsEx2.fs" id="Snippet3":::
- :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsEx2.vb" id="Snippet3":::
+ :::code language="csharp" source="~/snippets/csharp/System/IEquatableT/Equals/EqualsExample.cs" id="Person":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/IEquatableT/Equals/EqualsExample.fs" id="Person":::
+ :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsExample.vb" id="Person":::
- `Person` objects can then be stored in a object and can be identified by the `Contains` method, as the following example shows.
+ When a `Person` is stored in a , `Contains` uses its implementation to search for a match.
- :::code language="csharp" source="~/snippets/csharp/System/IEquatableT/Equals/Snippet12.cs" id="Snippet12":::
- :::code language="fsharp" source="~/snippets/fsharp/System/IEquatableT/Equals/Snippet12.fs" id="Snippet12":::
- :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/Snippet12.vb" id="Snippet12":::
+ :::code language="csharp" source="~/snippets/csharp/System/IEquatableT/Equals/EqualsExample.cs" id="PersonSample":::
+ :::code language="fsharp" source="~/snippets/fsharp/System/IEquatableT/Equals/EqualsExample.fs" id="PersonSample":::
+ :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsExample.vb" id="PersonSample":::
]]>