
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- How to use the Clear method of array class in C#?
- How to use the Clone() method of array class in C#?
- How to use the Copy(, ,) method of array class in C#
- How to use the CopyTo(,) method of array class in C#
- How to use the GetLength method of array class in C#?
- How to use the GetLongLength method of array class in C#?
- How to use the GetLowerBound method of array class in C#
- How to use the GetType method of array class in C#?
- How to use the GetUpperBound method of array class in C#?
- How to use the GetValue() method of array class in C#?
- How to use the IndexOf(,) method of array class in C#?
- How to use the Reverse() method of array class in C#
- How to use the Sort() method of array class in C#?
- How to use the substring() method of java.lang.String class in Java?
- How to use the Compare method of the string class in C#?

Advertisements