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 :: How to find out if a file exists in C# / .NET? 
Csharp :: c# remove all punctuation from string 
Csharp :: c# select a row from datagridview by value 
Csharp :: get file path in .net core from wwwroot folder 
Csharp :: c# check if char is string 
Csharp :: linq sum 
Csharp :: how get data from json in c# 
Csharp :: c# array max 
Csharp :: c# how to set string list 
Csharp :: dictionary to list c# 
Csharp :: c# add time to datetime 
Csharp :: linq when name then orderby 
Csharp :: entity framework insert 
Csharp :: maclaurin series 
Csharp :: c# clear an array 
Csharp :: replace first occurrence of character in string c# 
Csharp :: all Substring of String 
Csharp :: make 2D object move at constant speed unity 
Csharp :: c# func 
Csharp :: selenium scroll to element c# 
Csharp :: print a file from C# 
Csharp :: unity button not working 
Csharp :: append an array in c# 
Csharp :: exception handling in c# web api 
Csharp :: asp net img src path from database 
Csharp :: singleton pattern c# 
Csharp :: c# unit test for throwing exception method 
Csharp :: viewBag as a list 
Csharp :: Printing pattern in c# 
Csharp :: drop down list razor example 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =