Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# 8.0 using Range for multidimensional arrays

In C# 8.0, why can I use range on single dimensional arrays:

var oneDim = new int[5];
var oneDimSlice = oneDim[2..4];

But can not use it on multi dimensional arrays ?

var twoDim = new int[5, 5];
var twoDimSlice = twoDim[2..4, 2..4];
like image 292
koryakinp Avatar asked Mar 08 '19 14:03

koryakinp


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C language?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.

What is C full form?

Full form of C is “COMPILE”. One thing which was missing in C language was further added to C++ that is 'the concept of CLASSES'.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


1 Answers

https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/ranges-indexes

Array has more nuanced behavior. Single dimension arrays support both indices and ranges. Multi-dimensional arrays don't. The indexer for a multi-dimensional array has multiple parameters, not a single parameter. Jagged arrays, also referred to as an array of arrays, support both ranges and indexers.

so the answer is no, but it is possible to do it with jagged arrays if you are interested.

like image 116
Alex Avatar answered Oct 31 '22 07:10

Alex