Caminhoneiro

Convertion Types using as

Jul 17th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.38 KB | None | 0 0
  1.     class Person
  2.     {
  3.         public string Name { get; set; }
  4.     }
  5.  
  6.  
  7. [TestMethod]
  8.         public void AsBetter()
  9.         {
  10.             object name = "Sarah";
  11.  
  12.             Person p = name as Person;
  13.            
  14.             if (p == null)
  15.             {
  16.                 p = new Person { Name = "Default" };
  17.             }
  18.  
  19.             Debug.WriteLine(p.Name);
  20.         }
Advertisement
Add Comment
Please, Sign In to add comment