0

I'm working on an application that fills in a number of arrays. But being originally a VB6 application, it doesn't use element zero of any of them. This stops things like

my_array.Min

from working properly. I have no plans to tamper with the innards of the application, but it would be very convenient if I could specify a range of array elements in this sort of statement; something like

my_array(1:100).Min

Does such a construction exist, and if so, what is it?

1
  • What is Min? Can you show code that compiles in VB.NET? Commented Mar 13, 2013 at 15:48

1 Answer 1

2

Unfortunately .NET doesn’t have a convenient array slice construct1 (although you can use Linq to approximate it) but you’re solving the wrong X in an XY problem here.

The real solution is not to use 1-based arrays. Do change the innards of your application.

Incidentally, the default base for arrays in VB6 was also zero. You explicitly needed to specify Option Base 1 for 1-based arrays.


1 There’s ArraySegment(T) but before .NET 4.5 this structure was completely broken since it didn’t implement the IList(T) interface and was thus unusable. It does implement that now, but it’s too late – nobody is using the class.

Sign up to request clarification or add additional context in comments.

2 Comments

+1. I guess Brian is referring to code written by devs who were unaware of VB6's default behaviour, e.g. writing Dim a(5) and only accessing elements 1-5. This is a common problem. :-(
Thanks for that. Sigh. All I wanted to do was chop the unused bottom half off a graph, and now the worms are out of the can and wriggling everywhere. I suppose a man's gotta do what a man's gotta do...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.