Rearranged
On Fri, 6 Feb 2004 17:30:31 +0600, "Champika Nirosh"
<cn*****@textce ntric.lk> wrote:
"Joe Mayo [C# MVP]" <jm***@nospamAt CSharpDashStati on.com> wrote in message
news:e9******* *******@TK2MSFT NGP11.phx.gbl.. . >"Darryn Ross" <da****@datawav e.com.au> wrote in message news:uy******** ******@TK2MSFTN GP12.phx.gbl... >Hi...
>I am not sure how to test the type of an object that i define
>object a = "test" ;
>object b = 1 ;
>object c = true ;
>how do i test each of the three objects to find out what types they are..
e.g string, int, bool???
Hi Darryn,
You can use the 'is' operator:
if (a is string) {...}
If you wanted to find out what type it was you could do this:
string myTypeString = a.GetType().ToS tring();
Joe
--
http://www.csharp-station.com
I don't think so.. since at the creation level all three object are created
as object you wont be able to get the result you want with the given
solution
This is incorrect. Try running this:
using System;
namespace CSharpConsole
{
class Clarification
{
[STAThread]
static void Main(string[] args)
{
object anInt32 = 3;
int anotherInt32 = 4;
Console.WriteLi ne(
@"Every object ever created is of a specific type.
anotherInt32 is of type {0}.
mySecondInt is of type {1}",
anInt32.GetType ().Name,
anotherInt32.Ge tType().Name);
}
}
}
The type of the varible to which you assign a literal such as 1 or
"myString" doesn't affect the type of the literal. It may cause an
implicit conversion, or boxing, but that doesn't change the fact that
the original literal has its own well defined type.
/Magnus Lidbom