Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# get type of object

//Exact runtime type of the current instance.
object.GetType();
Comment

how to get type of an object in c#

class Animal { } 
class Dog : Animal { }

void PrintTypes(Animal a) { 
    Console.WriteLine(a.GetType() == typeof(Animal)); // false 
    Console.WriteLine(a is Animal);                   // true 
    Console.WriteLine(a.GetType() == typeof(Dog));    // true
    Console.WriteLine(a is Dog);                      // true 
}

Dog spot = new Dog(); 
PrintTypes(spot);
Comment

c# get type of class

Type tp = value.GetType();
Comment

how to find the type of a object c#

use the "is" keyword
Comment

PREVIOUS NEXT
Code Example
Csharp :: multiplication using arrays 
Csharp :: c# dictionary with multiple values 
Csharp :: remove duplicate characters in a string c# 
Csharp :: how to get previous page url aspnet core 
Csharp :: trim c# 
Csharp :: c# get battery level 
Csharp :: asp.net mvc get current url in view 
Csharp :: c# file watcher 
Csharp :: array sort C Sharp 
Csharp :: c# get custom attribute from property 
Csharp :: linq sum 
Csharp :: linq query get last day of month 
Csharp :: c# string list 
Csharp :: c# Predicate delegate 
Csharp :: c# string slice 
Csharp :: linq query select where c# 
Csharp :: c# how to crete array 
Csharp :: Write text in Word Document at specific location using C# 
Csharp :: published net core did not have wwwroot 
Csharp :: compact in laravrl 
Csharp :: c# online compiler 
Csharp :: autfac .net 6 
Csharp :: c# count directories in directory and subdirectories 
Csharp :: c# draw rectangle on screen 
Csharp :: Metadata publishing for this service is currently disabled 
Csharp :: convert object to iqueryable in c# 
Csharp :: c# entity framework get all records from table 
Csharp :: how to add data in list in c# 
Csharp :: unity ui button 
Csharp :: c# make a automapper 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =