Q:
C# program to convert a two-dimensional array into a one-dimensional array
belongs to collection: C# Basic Programs | array programs
C# Basic Programs | array programs
- C# | different types of one dimensional array declarations
- C# | printing an integer array using foreach loop
- C# | different types of two dimensional array declarations
- C# | Two dimensional array with fixed row size and variable columns size
- Find positive numbers from array of integers using C# program
- Find negative numbers from array of integers using C# program
- Find leap years form array of integers using C# program
- Print all Even numbers from array of integers using C# program
- Print all Odd numbers from array of integers using C# program
- Find largest element from an integer array in C#
- Find smallest element from integer array in C#
- Find palindrome numbers from array using C# program
- Insert an element at given position into array using C# program
- Reverse array elements using c# program
- Delete an element from given position from array using C# program
- Delete given element from array using C# program
- Find total number of occurrence of a given number using C# program
- Merge two arrays into third array using C# program
- C# program to make a simple ATM machine
- C# program to find the average of array elements
- C# program to convert a two-dimensional array into a one-dimensional array
- C# program to demonstrate the example of LongLength property of array
- C# program to print the lower bound and upper bound of an array
- C# program to find out the dimensions of an array
- C# program to demonstrate the example of BlockCopy() method of the array
- C# program to produce a third array by appending two different arrays
- C# program to search an item in an array using binary search
- C# program to implement indexer for an integer array
- C# program to convert negative values an integer array into positive
- C# program to get the length of a jagged array using predefine property
- C# program to find the smallest and largest elements of an array using predefined methods
- C# program to find the sum of array elements using the predefine Sum() method of Queryable class
- C# program to find the average of array elements using the predefine Average() method of Queryable class
- C# program to reverse an integer array using a predefined method
- C# program to sort an integer array using the predefined method
- C# program to add two matrices
- C# program to transpose a matrix
- C# program to print the upper triangular matrix
- C# program to print the lower triangular matrix
- C# program to check the matrix is an identity matrix or not
- C# program to find the largest element in the matrix
- C# program to multiply two matrices
- C# program to find the sum of each row of the matrix
- C# program to find the sum of each column of the matrix
- C# program to find the sum of the right diagonal of the matrix
- C# program to find the sum of the left diagonal of the matrix
- C# program to interchange the columns of the matrix
- C# program for swapping of two arrays
- C# program to insert an item into a sorted array
- C# program to delete an item from a sorted array
Program:
The source code to convert the two-dimensional array into a one-dimensional array in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created a class Demo that contains two arrays OneD and TwoD. Here we initialized TwoD array and also instantiate OneD array in the constructor of Demo class.
The Demo class contains ConverTwoDArrayToOneDArray() method to convert TwoD array into OneD array by assigning all elements. Here we also created PrintTwoArray() and PrintOneArray() methods.
The PrintTwoDArray() method will print elements of the TwoD array in the form of the matrix, and PrintOneDArray() will print all elements of the OneD array on the console screen.