Peter,
>int[] integerArray = new int[] { 1, 2, 3 };
>List<double> doubleList = new List<double>();
[quoted text clipped - 8 lines]
>double[] doubleArray =
> (from currentValue in integerArray select (double)currentValue).ToArray();
Wouldn't
double [] doubleArray = integerArray.Cast<double>().ToArray();
do too?
Regards,
Gilles.
Jon Skeet [C# MVP] - 25 Mar 2008 21:23 GMT
> Wouldn't
>
> double [] doubleArray = integerArray.Cast<double>().ToArray();
>
> do too?
I believe it would right now, but it shouldn't, and it won't with .NET
3.5 SP1.
http://blogs.msdn.com/ed_maurer/archive/2008/02/16/breaking-change-in-
linq-queries-using-explicitly-typed-range-variables.aspx

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Peter Duniho - 25 Mar 2008 21:46 GMT
> I believe it would right now, but it shouldn't, and it won't with .NET
> 3.5 SP1.
>
> http://blogs.msdn.com/ed_maurer/archive/2008/02/16/breaking-change-in-
> linq-queries-using-explicitly-typed-range-variables.aspx
Ah. I was wondering about that. :) I was actually surprised when I
wrote my little test code to see if Cast<T> worked to find that it did.
Before the test, I'd assumed it would literally just try to cast to the
target type.
I was pleasantly surprised that it did more than that.
Of course, that happiness was short-lived. Thanks for pulling the rug
out. :)
Pete
Gilles Kohl [MVP] - 25 Mar 2008 22:34 GMT
>> Wouldn't
>>
[quoted text clipped - 7 lines]
>http://blogs.msdn.com/ed_maurer/archive/2008/02/16/breaking-change-in-
>linq-queries-using-explicitly-typed-range-variables.aspx
Good to know Jon, thanks for the pointer.
Regards,
Gilles.
> int[] integerArray = new int[] { 1, 2, 3 };
> List<double> doubleList = new List<double>();
> foreach (int i in integerArray)
> doubleList.Add((double)i);
>
> double[] doubleArray = doubleList.ToArray();
I think I'd pre-allocate the List<T> in this case:
List<double> doubleList = new List<double>(integerArray.Length);
> or using Linq
>
> int[] integerArray = new int[] { 1, 2, 3 };
> double[] doubleArray =
> (from currentValue in integerArray select
> (double)currentValue).ToArray();
That works. Or this too:
double[] doubleArray = integerArray.Cast<double>().ToArray();
Pete
CSharper - 25 Mar 2008 21:17 GMT
On Mar 25, 3:12 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> On Tue, 25 Mar 2008 12:53:41 -0700, Peter Morris <peter[dot]morris
>
[quoted text clipped - 22 lines]
>
> Pete
I really like what linq brings to C#3.0.
Peter Duniho - 25 Mar 2008 21:24 GMT
> I really like what linq brings to C#3.0.
Me too. Though, ironically, I have found that for my own purposes,
because I am so rarely writing any code that uses a database, I'm never
using the database-oriented aspects of LINQ.
Even though my first exposure to it was in situations specifically
referencing database manipulation, and even though the power of LINQ
appears to be most directly applicable in that context, and even though
the examples I continue to be exposed to are most often in that context,
it turns out it's very useful for other more mundane things as well. :)
But yes, it's a very nice addition, as is the extension methods feature
that makes much of what's in LINQ possible (especially the stuff I'm using
:) ).
Pete
Peter Morris - 26 Mar 2008 10:01 GMT
Currently I mainly use linq to populate ViewData in a website without giving
access to the objects themselves.....
ViewData["OrderLines"] =
from line in order.Lines
select new
{
LineNumber = line.LineNumber,
ProductName = line.Product.Name,
QuantityOrdered = line.QuantityOrdered,
etc = line.etc
};
:-)
Pete
Jon Skeet [C# MVP] - 25 Mar 2008 21:24 GMT
<snip>
> That works. Or this too:
>
> double[] doubleArray = integerArray.Cast<double>().ToArray();
As I replied to Gilles (just repeating myself as this could be a
dangerously seductive answer otherwise) - that works now, but will
probably break with .NET 3.5 SP1.
http://blogs.msdn.com/ed_maurer/archive/2008/02/16/breaking-change-in-
linq-queries-using-explicitly-typed-range-variables.aspx

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk