Interface iface
{
string name {get;set;}
void show();
}
struct xyz:iface
{
//code here
}
I want to know the xyz.name will store in stack of heap.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
syed abidPosted Jul 5, 2010, 12:58 PM
Sam HobbsPosted Jul 4, 2010, 1:07 PM
An interface does not have an implementation so it is not allocated anywhere. When the xyz struct is declared, it will exist in the stack, correct? That would include the string name. Are you asking because you are not sure whether xyz.name will be modified in functions without ref? Try it and see.
using System;
namespace TestConsole
{
public interface iface
{
string name { get; set; }
void show();
}
struct xyz : iface
{
public string name { get; set; }
public void show() { }
}
class Program
{
static void Main(string[] args)
{
xyz test = new xyz();
test.name = "Initial";
WithoutRef(test);
Console.WriteLine(test.name);
WithRef(ref test);
Console.WriteLine(test.name);
}
static void WithoutRef(xyz test)
{
test.name = "WithoutRef";
}
static void WithRef(ref xyz test)
{
test.name = "WithRef";
}
}
}