[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Pnet-developers] [bugs #11998] Problems with casting arrays, isins
From: |
Marcus |
Subject: |
Re: [Pnet-developers] [bugs #11998] Problems with casting arrays, isinst, and the as operator |
Date: |
Thu, 17 Feb 2005 13:18:42 -0600 |
User-agent: |
KMail/1.7.92 |
The test case was designed to illustrate the incorrect behavior under Pnet.
The code that I am writing is more complex.
Specifically, I am working on some performance enhancements to the
System.Array.Sort() set of methods. These overloaded methods all take
parmeters of type Array. The Array type is very general and supports things
like multi-dimensional arrays and arrays that are not zero-based.
In some cases, it is possible to enhance performance greatly, but it requires
the ability to attempt casting an Array to object[] without generating an
exception in the case of failure. The "as" operator provides that
functionality. This is important because only some arrays passed to
Array.Sort() will be able to be cast this way.
On Thursday 17 February 2005 2:13 am, James Michael DuPont wrote:
> Follow-up Comment #2, bugs #11998 (project dotgnu-pnet):
>
> The workaround is to cast the object directly without as.
> the test file shows that this works, and the data is preserved.
> using System;
>
> public class Testing
> {
> public static void Main()
> {
>
> String foo = "fooo";
> Console.WriteLine(foo == null );
>
> object z= foo as object;
> Console.WriteLine(z == null );
>
> Array x = new string[1];
> x[0]=foo;
> Console.WriteLine(x == null );
>
> Console.WriteLine("raw");
> Console.WriteLine(x);
>
> Console.WriteLine("as object");
> Console.WriteLine(x as object[]);
>
> Console.WriteLine("cast ");
> Console.WriteLine((object[])x);
>
> Console.WriteLine("cast2 ");
> object[] y = (object[])x;
> Console.WriteLine(y == null );
> Console.WriteLine(y);
> Console.WriteLine(y[0]);
>
> Console.WriteLine("cast as ");
> object[] z2 = x as object[];
> Console.WriteLine(z2 == null );
>
> }
> }
- [Pnet-developers] [bugs #11998] Problems with casting arrays, isinst, and the as operator, Marcus Urban, 2005/02/16
- [Pnet-developers] [bugs #11998] Problems with casting arrays, isinst, and the as operator, Marcus Urban, 2005/02/17
- [Pnet-developers] [bugs #11998] Problems with casting arrays, isinst, and the as operator, James Michael DuPont, 2005/02/17
- Re: [Pnet-developers] [bugs #11998] Problems with casting arrays, isinst, and the as operator,
Marcus <=
- [Pnet-developers] [bugs #11998] Problems with casting arrays, isinst, and the as operator, Klaus Treichel, 2005/02/19
- [Pnet-developers] [bugs #11998] Problems with casting arrays, isinst, and the as operator, Klaus Treichel, 2005/02/19