Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Store Different Data Types Value in Array
WhatsApp
Vishvajeet Pawar
10y
14
k
0
0
25
Blog
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
Up Next
Understanding Value Types And Reference Types In C# Using Classes, Structs And, Enums
Ebook Download
View all
Diving Into OOP
Read by 16.1k people
Download Now!
Learn
View all
Membership not found