Ah, Bill's right. My recollection was incorrect. I was actually thinking about
the indexing, and thought that also applied to length checks.
With regards the indexing, for example, this will work with Option Strict On
(excuse if there is a more concise syntax, I couldn't work it out):
Dim names As String() = New String() {"David", "Bill", "Anthony"}
Dim sortedNames As IEnumerable(Of String) = names.OrderBy(Function(n) n)
Console.WriteLine(sortedNames(0))
Basically under the covers the compiler calls Enumerable.ElementAtOrDefault.
-----Original Message-----
From: David Kean
Sent: Wednesday, February 16, 2011 6:50 PM
To: ozDotNet
Subject: RE: LINQ extensions
Hmm...that wasn't to my recollection. I could have sworn that it allowed
indexing and length checks even if the underlying implementations didn't
support it (ie not via late binding). Unfortunately VS stopped working on my
phone so I'll need to wait until I get in back in the office to play around.
Sent from my Windows Phone
-----Original Message-----
From: Bill McCarthy
Sent: Wednesday, February 16, 2011 6:28 PM
To: 'ozDotNet'
Subject: RE: LINQ extensions
That's only if you have Strict Off and use late binding.
|-----Original Message-----
|From: [email protected] [mailto:ozdotnet-
|[email protected]] On Behalf Of David Kean
|Sent: Thursday, 17 February 2011 1:18 PM
|To: ozDotNet
|Subject: RE: LINQ extensions
|
|Not true - try this in VB.
|
|Sent from my Windows Phone
|________________________________
|
|From: Tristan Reeves
|Sent: Wednesday, February 16, 2011 5:24 PM
|To: ozDotNet
|Subject: Re: LINQ extensions
|
|
|That's true, but you never would, with or without linq. That is because
|IEnumerable does not have such a property.
|
|
|On Wed, Feb 16, 2011 at 4:55 PM, James Chapman-Smith
|<[email protected]> wrote:
|
|
| LINQ doesn't cause `.Length` to disappear, but if you assign the
array to
|an `IEnumerable<T>` then you won't seen the `.Length` property.
|
|
|
| From: [email protected] [mailto:ozdotnet-
|[email protected]] On Behalf Of Tristan Reeves
| Sent: Wednesday, 16 February 2011 11:54
|
|
| To: ozDotNet
| Subject: Re: LINQ extensions
|
|
|
|
|
|
|
| But Length is always a (valid) property of arrays, whether or
| not
LINQ is
|reference. Or are you saying that Length "disappears" when LINQ is
|referenced?
|
|
|
| Tristan.
|
| On Tue, Feb 15, 2011 at 4:23 PM, Ian Thomas
|<[email protected]>
|wrote:
|
| Michael - slip of the fingers - yes, it was a .Count method
| (when
LINQ is
|referenced), and a .Length property (when not). Not weird, lang c#
|
|
|
|
|________________________________
|
|
| Ian Thomas
| Victoria Park, Western Australia
|
|
|________________________________
|
|
| From: [email protected] [mailto:ozdotnet-
|[email protected]] On Behalf Of Michael Minutillo
| Sent: Tuesday, February 15, 2011 1:20 PM
| To: ozDotNet
| Subject: Re: LINQ extensions
|
|
|
| Weird. It should add a .Count() extension method, not a property.
Are
|you coding in a language that has optional parentheses by any chance?
|
| On Tue, Feb 15, 2011 at 1:12 PM, Ian Thomas
|<[email protected]>
|wrote:
|
| FYI only
|
| Just an oddity I hadn't taken in before, that a reference to
| LINQ
makes
|.Count a valid property of arrays (otherwise .Length is valid).
|
| I had been using LINQ to Objects in a small projects and changed
| it
to
|not do so, meticulously cleaned references to LINQ out (VS2008 does not
seem
|to do that thoroughly), and had a couple of errors arise with
myarrays.Count
|statements I had been slack enough to write previously.
|
| Framework 3.5
|
|
|________________________________
|
|
| Ian Thomas
| Victoria Park, Western Australia
|
|
|
|
|