TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Store Different Data Types Value in Array
Vishvajeet Pawar
Nov 17, 2014
13.9
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog, I want to explain how to store Different Data Types Value in Array?
Array
Array means collection of similar Data Types or Store Collection of similar Data Types Value in Array.
Ex:
int
[] no =
new
int
[2];
We declare or Create integer type array as "no". We can store only integer value not like string,bool etc.
int
[] no =
new
int
[2];
no[0] = 9080;
no[1] = 8090;
We want to store any data type value other than int then show error as
But we can store different data type value in array as;
namespace
Array
{
class
Program
{
static
void
Main(
string
[] args)
{
bool
b =
true
;
object
[] obj =
new
object
[3];
obj[0] = 1;
obj[1] =
"Vishu"
;
obj[2] = b;
Console.WriteLine(
"value of Array 0 as"
+
" "
+ obj[0] +
" "
);
Console.WriteLine();
Console.WriteLine(
"and value of array 1 as"
+
" "
+ obj[1] +
""
);
Console.WriteLine();
Console.WriteLine(
"and value of array 2 as"
+
" "
+ obj[2] +
""
);
Console.ReadLine();
}
}
}
Object
Object is Reference Type , you can assign any value type and reference type variable to object data type.
Output
Store Different Data Types Value in Array
Next Recommended Reading
Understanding Value Types And Reference Types In C# Using Classes, Structs And, Enums