Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

jagged array to 2d array c#

static T[,] To2D<T>(T[][] source)
{
    try
    {
        int FirstDim = source.Length;
        int SecondDim = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular

        var result = new T[FirstDim, SecondDim];
        for (int i = 0; i < FirstDim; ++i)
            for (int j = 0; j < SecondDim; ++j)
                result[i, j] = source[i][j];

        return result;
    }
    catch (InvalidOperationException)
    {
        throw new InvalidOperationException("The given jagged array is not rectangular.");
    } 
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: combobox in datagrid wpf 
Csharp :: entity framework with query C# 
Csharp :: string interpolation in c# 
Csharp :: how to get the today date in c# 
Csharp :: c# generate random int list 
Csharp :: properties in c# 
Csharp :: reverse a linked list C# 
Csharp :: c# divide two integers get float 
Csharp :: C# Convert 1 range to another 
Csharp :: unity scene switch 
Csharp :: how to check type in c# 
Csharp :: sucess messages in c# 
Csharp :: indexof c# 
Csharp :: How to make enemy shooting 
Csharp :: display array elemetns to text box c# 
Csharp :: c# get every point in a line in matrix 
Csharp :: how to get relative path in c# 
Csharp :: number to character c# 
Csharp :: administration 
Csharp :: Block iFrames | How to Stop Your Website From Being iFramed 
Csharp :: bind repeater to dictionary 
Csharp :: unity audiosource play 
Csharp :: c# unit test exception using try catch 
Csharp :: c# copy bidimensional array 
Csharp :: enum in combobox wpf 
Csharp :: Severity Code Description Project File Line Suppression State Error MSB3021 
Csharp :: wpf databinding 
Csharp :: c# mysql select into datatable 
Csharp :: dotnet create web api 
Csharp :: get xml from url 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =