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 are lambda expressions used for?
In which way a two-dimensional array declared in C#?
What are the Types of JIT and what is econo-JIT
How will U encapsulate button trigger event into text_box event of Pressing Enter key?
What is the difference between field and property in c#?
What is tryparse?
What is difference between var dynamic and object in c#?
How to navigate from one page(form) to another page(form) using C#.net...please give me the example
What is the ouput of the following program?
Wht executescaler method is used?
What is the difference between interface and inheritance in c#?
What is expression c#?