- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 use the SetValue(,) method of array class in C#?
The SetValue() method sets a value to the element at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.
Firstly, set the array.
Array arr = Array.CreateInstance(typeof(String), 6);
No set values to the element using the SetValue() method.
arr.SetValue("One", 0); arr.SetValue("Two", 1); arr.SetValue("Three", 3); arr.SetValue("Four", 4); arr.SetValue("Five", 5);
The following is an example showing the usage of SetValue() method in C#.
Example
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class Program { static void Main(string[] args) { Array arr = Array.CreateInstance(typeof(String), 6); arr.SetValue("One", 0); arr.SetValue("Two", 1); arr.SetValue("Three", 3); arr.SetValue("Four", 4); arr.SetValue("Five", 5); Console.WriteLine("Length {0}",arr.GetLength(0).ToString()); Console.ReadLine(); } } }
Output
Length 6
Advertisements