Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
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
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to Declare Structure and Assign the Value and Call in C#
WhatsApp
Rajan Singh
Jun 24
2015
1.1
k
0
0
using
System.IO;
using
System;
class
Complex
{
public
int
x;
public
int
y;
}
struct
Real
{
public
int
x;
public
int
y;
}
class
StructureAndClassAssignment
{
static
void
Main(
string
[] args)
{
Complex complexNumber1 =
new
Complex();
complexNumber1.x = 10;
complexNumber1.y = 20;
Complex complexNumber2 = complexNumber1;
complexNumber1.x = 1000;
complexNumber1.y = 2000;
Console.WriteLine(
"Class: x:{0}, y:{1}"
, complexNumber2.x, complexNumber2.y);
Real realNumber1 =
new
Real();
realNumber1.x = 100;
realNumber1.y = 200;
Real realNumber2 = realNumber1;
realNumber1.x = 10;
realNumber1.y = 20;
Console.WriteLine(
"Struct: x:{0}, y:{1}"
, realNumber2.x, realNumber2.y);
}
}
Output:
Class: x:1000, y:2000
Struct: x:100, y:200
C#
structure in C#
Up Next
How to Declare Structure and Assign the Value and Call in C#