
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use the GetType method of array class in C#?
The GetType() method of array class in C# gets the Type of the current instance (Inherited from Object).
To get the type.
Type tp = value.GetType();
In the below example, we are checking the int value using the type.
if (tp.Equals(typeof(int))) Console.WriteLine("{0} is an integer data type.", value)
The following is the usage of GetType() method in C#.
Example
using System public class Program { public static void Main() { object[] values = { (int) 100, (long) 17111}; foreach (var value in values) { Type tp = value.GetType(); if (tp.Equals(typeof(int))) Console.WriteLine("{0} is aninteger data type.", value); else Console.WriteLine("'{0}' is not an int data type.", value); } } }
- Related Questions & Answers
- How to use the Clear method of array class in C#?
- How to use the Clone() method of array class in C#?
- How to use the Copy(, ,) method of array class in C#
- How to use the CopyTo(,) method of array class in C#
- How to use the GetLength method of array class in C#?
- How to use the GetLongLength method of array class in C#?
- How to use the GetLowerBound method of array class in C#
- How to use the GetUpperBound method of array class in C#?
- How to use the GetValue() method of array class in C#?
- How to use the IndexOf(,) method of array class in C#?
- How to use the Reverse() method of array class in C#
- How to use the SetValue(,) method of array class in C#?
- How to use the Sort() method of array class in C#?
- How to use the Compare method of the string class in C#?
- How to use the ToString() method of array in C#?
Advertisements