

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 assign multiple values to same variable in C#?
To set multiple values to same variable, use arrays in C#. Let’s say instead of taking 5 variables, set these 5 variables using arrays in a single variable.
The following is an example to set three values to a single variable with a string array −
string[] arr = new string[3];
Let us now initialize it −
string[] arr = new string[3] {"one", "two", "three"};
The following is the complete example −
Example
using System; public class Demo { static void Main(string[] args) { string[] arr = new string[3] {"one", "two", "three"}; for (int i = 0; i < arr.Length; i++) { Console.WriteLine("Values: " + arr[i]); } Console.ReadKey(); } }
Output
Values: one Values: two Values: three
- Related Questions & Answers
- How to assign multiple values to a same variable in Python?
- Assign multiple variables to the same value in JavaScript?
- How to assign same value to multiple variables in single statement in C#?
- Assign other value to a variable from two possible values in C++
- How to assign a reference to a variable in C#
- How to assign int value to char variable in Java
- Assign multiple variables with a Python list values
- How to assign values to variables in C#?
- How to assign values to variables in Python
- Remove same values from array containing multiple values JavaScript
- How can we assign a function to a variable in JavaScript?
- How do we assign values to variables in Python?
- How do I assign a dictionary value to a variable in Python?
- Can we assign a reference to a variable in Python?
- How to assign the result of a MySQL query into a variable?
Advertisements