I converted the following quer开发者_如何转开发y from C#:
src.Select((c, i) => src.Substring(i)).Count(sub => sub.StartsWith(target))
to the VB.NET query:
src.[Select](Function(c, i) src.Substring(i)).Count(Function([sub]) [sub].StartsWith(target))
Using Developer Fusion. I was just wondering why the VB.NET version has [] throughout.
select
and sub
are keywords in VB.NET
Sub
and Select
are keywords in VB.NET, so you have to mark them especially to be able to use them as variable names - in general using keywords as variable names should be avoided - just rename them and you can get rid of the braces.
The reason why is that both Select
and Sub
are reserved words in VB.Net. The []
surrounding them is an escaping mechanism that causes them to not be treated as keywords
A minor point: the .Select
doesn't need the brackets:
src.Select(Function(c, i) src.Substring(i)).Count(Function([sub]) [sub].StartsWith(target))
works fine.
精彩评论