benjaminvr

Object type checking

Nov 27th, 2021
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. using System;
  2.  
  3. public class MijnKlasse {
  4.     public string a = "b";
  5.     public string b => "c";
  6.     public string c {get;set;}
  7.    
  8.     public MijnKlasse(string val="d"){
  9.         c = val;
  10.     }
  11. }
  12.                    
  13. public class Program
  14. {
  15.     public static void Main()
  16.     {
  17.         MijnKlasse instantie = new MijnKlasse();
  18.        
  19.         Console.WriteLine(instantie.GetType().IsClass);  // 1
  20.         Console.WriteLine(typeof(MijnKlasse) == typeof(object));  // 0
  21.         Console.WriteLine(instantie.GetType() == typeof(object)); // 0
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment