Skip to content

Commit 7806c5c

Browse files
authored
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.
1 parent 07acbe7 commit 7806c5c

File tree

1 file changed

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

1 file changed

+3
-7
lines changed

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

Lines changed: 3 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,8 @@ 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+
if (nameValue == null || nameValue.Length == 0)
60+
throw new ArgumentException(nameof(nameValue));
6561

6662
handleValue = CreateMutex(mutexAttrValue,
6763
true, nameValue);
@@ -105,4 +101,4 @@ public void Release()
105101
ReleaseMutex(handleValue);
106102
}
107103
}
108-
//</Snippet1>
104+
//</Snippet1>

0 commit comments

Comments
 (0)