So I just started in C# coming from a Matlab/Python background. What I do miss the most are advanced indexing queries like:
a = [1 2 3 4;5 6 7 8];
b = a[2,2:4]; // Gives: b = [6 7 8];
In C# (and most other programming languages) I have several possibilities to achieve that:
- by using loops. Higher-dimensional arrays will yield lots of (similar) code
- using LINQ: a big library, and the syntax still seems cumbersome and slow to me.
- Extending the Array like here on dotnetperls.com, but this won't work with the bracket operator, but gets closer to the idea
- Writing my own class, however I won't be able to inherit from System.Array
So to me it looks like it should be "doable" to implement a calls like this to arrays:
b = a["1,1:3"]; // compare to example above, just 0-based indexing here
So what I want to do is
- overload the Array class / Inherit a class from Array class (so it remains generic)
- add custom bracket indexing with string parsing
Without writing too much code. Am I missing something?
Please note: this is rather an exercise for me than an actual task. So I know I could use Python and compile the code. I am just wondering if it is possible at all and if so, which way is the best to do it.