Skip to content

Commit c6796f4

Browse files
Copilotadegeo
andcommitted
Change null check to type check for Person in ObsoleteGetDataExample
Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
1 parent 47a51b2 commit c6796f4

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

dotnet-desktop-guide/winforms/migration/snippets/clipboard-dataobject-net10/net/csharp/ObsoletePatterns.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ public static void ObsoleteGetDataExample()
3232
object data = Clipboard.GetData("MyApp.Person"); // Obsolete method
3333

3434
// Returns a NotSupportedException instance for a custom object type
35-
if (data != null)
35+
if (data is Person person)
3636
{
37-
Person person = (Person)data;
3837
Console.WriteLine($"Processing person: {person.Name}, Age: {person.Age}");
3938
}
4039
}

dotnet-desktop-guide/winforms/migration/snippets/clipboard-dataobject-net10/net/vb/ObsoletePatterns.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Namespace ClipboardExamples
2727
Dim data As Object = Clipboard.GetData("MyApp.Person") ' Obsolete method
2828

2929
' Returns a NotSupportedException instance for a custom object type
30-
If data IsNot Nothing Then
30+
If TypeOf data Is Person Then
3131
Dim person As Person = CType(data, Person)
3232
Console.WriteLine($"Processing person: {person.Name}, Age: {person.Age}")
3333
End If

0 commit comments

Comments
 (0)