Ali Shah
asked on
Equivalent of New String("") in C#
hi there i have a variable of object type in my C# method
object objReplacer.
i want to check the type of a value returned in another variable and if the value is typeof string then i want the equivalent of this in C#
ObjReplacer = New String("") (This is VB.Net code i want equivalent of this in C#)
kind regards
object objReplacer.
i want to check the type of a value returned in another variable and if the value is typeof string then i want the equivalent of this in C#
ObjReplacer = New String("") (This is VB.Net code i want equivalent of this in C#)
kind regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hii
you may write it like this:
object o = "Some string";
The static type of the variable is object, but at run time, the type of the variable's referent is string. Therefore, the next line will print "System.String" to the console:
Console.WriteLine(o.GetTyp e());
you may write it like this:
object o = "Some string";
The static type of the variable is object, but at run time, the type of the variable's referent is string. Therefore, the next line will print "System.String" to the console:
Console.WriteLine(o.GetTyp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh thanks a lot. Yes it is cleaner and works fine
regards,
regards,
I would have expected, at least, a split with Guy Hengel's comment (http:#a39942451), since he answered your original question.
ASKER
Oh thanks how can i edit this now? or should we ask moderator to make a split?
Use the "Request Attention" link below your original question.
ASKER
if (strDBType.GetType() == typeof(char) || strDBType.GetType() == typeof(string) || strDBType.GetType() == typeof(DateTime))
{
objREplacer = string.Empty;
}
else if (strDBType.GetType() == typeof(int))
{
objREplacer = new int();
objREplacer = 0;
}
else if (strDBType.GetType() == typeof(decimal))
{
objREplacer = new decimal();
objREplacer = 0.0;
}
???????