Dear All
I have a small problem with using as operator on value type array.
Here is an example what I am trying to do.
using System;
using System.Collecti ons.Generic;
using System.Text;
namespace TestDynamicCast
{
class Program
{
static void Main(string[] args)
{
uint[] array1 = { uint.MaxValue - 1, uint.MaxValue - 2 };
MyMethod(array1 );
}
public static void MyMethod(Array arr)
{
int[] afterCast1 = arr as int[];
if (null != afterCast1) //cast is successfull. Is it correct?
{
//DoSomeThing
}
else
{
float[] afterCast2 = arr as float[];
if (null != afterCast2) //cast fails which is OK
{
//DoSomeThingElse
}
}
}
}
}
I think first 'if' condition itself must fail because int[] and uint[] are
not same, but it's able cast it successfully.
Please let me know what's going wrong with my code and how to solve this
problem
Thanks in advance.
_______________ _______________ _______________ _______________ _______________ __
Krishna Rao K
Lucid Software Ltd 104, NSIC STP Complex | Guindy Industrial Estate |
Ekkattuthangal | Chennai 600032 ' +91 44 2225 2273 / 76 , +91 98407 28998
_______________ _______________ _______________ ___________
I have a small problem with using as operator on value type array.
Here is an example what I am trying to do.
using System;
using System.Collecti ons.Generic;
using System.Text;
namespace TestDynamicCast
{
class Program
{
static void Main(string[] args)
{
uint[] array1 = { uint.MaxValue - 1, uint.MaxValue - 2 };
MyMethod(array1 );
}
public static void MyMethod(Array arr)
{
int[] afterCast1 = arr as int[];
if (null != afterCast1) //cast is successfull. Is it correct?
{
//DoSomeThing
}
else
{
float[] afterCast2 = arr as float[];
if (null != afterCast2) //cast fails which is OK
{
//DoSomeThingElse
}
}
}
}
}
I think first 'if' condition itself must fail because int[] and uint[] are
not same, but it's able cast it successfully.
Please let me know what's going wrong with my code and how to solve this
problem
Thanks in advance.
_______________ _______________ _______________ _______________ _______________ __
Krishna Rao K
Lucid Software Ltd 104, NSIC STP Complex | Guindy Industrial Estate |
Ekkattuthangal | Chennai 600032 ' +91 44 2225 2273 / 76 , +91 98407 28998
_______________ _______________ _______________ ___________
Comment