c# - How to determine Type of value types -



c# - How to determine Type of value types -

this question has reply here:

how check if object not of particular type? 6 answers

how find type of value type in c#?

let's have:

string str; int value; double doublevalue;

is there method returns type of of these value types?

to clearer, trying this:

string str = "hello"; string typeofvalue = <call method returns type of variable `str`> if (typeofvalue == "string") { //do } else { //raise exception }

i want input user , raise exception if value entered not string or int or double depending on conditions.

i have tried:

public class test { public static void main(string[] args) { int num; string value; console.writeline("enter value"); value = console.readline(); bool isnum = int32.tryparse(value, out num); if (isnum) { console.writeline("correct value entered."); } else { console.writeline("wrong value entered."); } console.readkey(); } }

but if type of value want check string or else?

you can utilize gettype on element in .net since exists @ object level :

var mystringtype = "string".gettype(); mystringtype == typeof(string) // true

gettype returns type object, can readable human friendly name using name property on type.

c#

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -