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
How to Declare Structure and Assign the Value and Call in C#
Rajan Singh
Jun 24
2015
Code
990
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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#