Skip to content

Commit c88c7de

Browse files
Update sample.cs (#8741)
* Update sample.cs - Fix first if-statement in Create method: currently checks to see if `nameValue == null` **and** `nameValue.Length == 0`. Should check if one or the other. - Change exception thrown from above if-statement from `ArgumentNullException` to `ArgumentException` and replaced argument with `nameof` expression. - Remove unnecessary empty lines. * Apply suggestions from code review --------- Co-authored-by: Genevieve Warren <[email protected]>
1 parent 0bb5c05 commit c88c7de

File tree

1 file changed

+2
-7
lines changed
  • snippets/csharp/Microsoft.Win32.SafeHandles/SafeWaitHandle/Overview

1 file changed

+2
-7
lines changed

snippets/csharp/Microsoft.Win32.SafeHandles/SafeWaitHandle/Overview/sample.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55

66
class SafeHandlesExample
77
{
8-
98
static void Main()
109
{
1110
UnmanagedMutex uMutex = new UnmanagedMutex("YourCompanyName_SafeHandlesExample_MUTEX");
1211

1312
try
1413
{
15-
1614
uMutex.Create();
1715
Console.WriteLine("Mutex created. Press Enter to release it.");
1816
Console.ReadLine();
@@ -58,10 +56,7 @@ public UnmanagedMutex(string Name)
5856

5957
public void Create()
6058
{
61-
if (nameValue == null && nameValue.Length == 0)
62-
{
63-
throw new ArgumentNullException("nameValue");
64-
}
59+
ArgumentException.ThrowIfNullOrEmpty(nameValue);
6560

6661
handleValue = CreateMutex(mutexAttrValue,
6762
true, nameValue);
@@ -105,4 +100,4 @@ public void Release()
105100
ReleaseMutex(handleValue);
106101
}
107102
}
108-
//</Snippet1>
103+
//</Snippet1>

0 commit comments

Comments
 (0)