can a structure used in a class if yes then how.

Answers were Sorted based on User's Feedback



can a structure used in a class if yes then how...

Answer / jj

This example shows that when a struct is passed to a method,
a copy of the struct is passed, but when a class instance is
passed, a reference is passed.

// struct2.cs
using System;

class TheClass
{
public int x;
}

struct TheStruct
{
public int x;
}

class TestClass
{
public static void structtaker(TheStruct s)
{
s.x = 5;
}
public static void classtaker(TheClass c)
{
c.x = 5;
}
public static void Main()
{
TheStruct a = new TheStruct();
TheClass b = new TheClass();
a.x = 1;
b.x = 1;
structtaker(a);
classtaker(b);
Console.WriteLine("a.x = {0}", a.x);
Console.WriteLine("b.x = {0}", b.x);
}
}

Output

a.x = 1
b.x = 5

From MSDN:

Is This Answer Correct ?    6 Yes 0 No

can a structure used in a class if yes then how...

Answer / radhika

yes we can use the structure in a class.

Is This Answer Correct ?    4 Yes 2 No

Post New Answer

More C Sharp Interview Questions

What is the usage of transponders?

0 Answers   Wipro,


Indexers in c#?

8 Answers   Intaglio, Microsoft, TCS,


What is delegate in c#?

0 Answers  


What is the difference between == and object.equals?

0 Answers  


Which debugging tools you can use in the .NET ssSDK?

0 Answers   Siebel,






What is a jagged array?

0 Answers  


Are c# destructors the same as c++ destructors?

0 Answers  


FOR EXAMPLE : CLASS Dotnet { } creating object: Dotnet dn=new Dotnet(); NOW THE QUESTION IS WHICH IS CALLED AS OBJECT ?EITHER dn OR new Dotnet() and CAN YOU PROVE YOUR ANSWER?????PLEASE REPLY...

1 Answers  


How do you escape in c#?

0 Answers  


Does c# do array bounds checking?

0 Answers  


what are the best design patterns for C#.Net?

1 Answers  


What is data annotation in c#?

0 Answers  


Categories