can a structure used in a class if yes then how.
Answers were Sorted based on User's Feedback
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 |
What is Wrapper class in dot net?
What are the advantages of clr procedure over t-sql procedure?
What is desktop example?
Explain Direct CAST vs CType ?
What is cookies in c# asp net?
What do you mean by thread safe in c#?
What are the applications of c#?
What are virtual destructors?
0 Answers InfoAxon Technologies,
What is difference between singleordefault and firstordefault?
In the page load event I assigned dropdownlist’s datasource property to a valid list. On the submit button click.. The same datasource property is coming as null. Why?
Why we can't create the object of abstract class ?
15 Answers Assyst, CTS, HCL, IBM, L&T,
Explain types of comment in c# with examples
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)