Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is gui in c#?

957


Could you explain the difference between func vs action vs predicate?

843


What is a byte in c#?

961


What is private void in c#?

900


What is a cshtml file?

1054


Can you instantiate a struct without using a new operator in c#?

929


What is an event in c#?

875


What is the ouput of the following program?

955


How many bytes is an int in c#?

919


Write a program in c# to find the angle between the hours and minutes in a clock?

900


What is datagrid c#?

922


What are extender provider components? Explain how to use an extender provider in the project.

891


What is the concept of strong names?

967


What are jagged arrays used for?

922


What is .net c#?

887