Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to input multiple values from user in one line in C#?
Use a while loop to input multiple values from the user in one line.
Let’s say you need to get the elements of a matrix. Get it using Console.ReadLine() as shown below −
Console.Write("
Enter elements - Matrix 1 : ");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
arr1[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
The following is an example showing how we can input multiple values from user −
Example
using System;
namespace Demo {
public class Program {
public static void Main(string[] args) {
int[,] arr1 = new int[10, 10];
int i, j;
Console.Write("
Enter Matrix elements: ");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
arr1[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
}
}
}
Output
Enter Matrix elements:
Advertisements