Given
class Foo : Attribute
{
public int I { get; set; }
}
struct Foo2
{
public int I { get; set; }
}
And
private static void Method1(Foo foo)
{
foo.I = 1;
}
private static void Method2(Foo2 foo2)
{
foo2.I = 1;
}
Usage
var foo = new Foo();
//IL_0001: newobj instance void ConsoleApp3.Foo::.ctor()
//IL_0006: stloc.0 // foo
var foo2 = new Foo2();
//IL_0007: ldloca.s foo2
//IL_0009: initobj ConsoleApp3.Foo2
Method1(foo);
//IL_0000: nop
//IL_0001: ldarg.0 // foo
//IL_0002: ldc.i4.1
//IL_0003: callvirt instance void ConsoleApp3.Foo::set_I(int32)
//IL_0008: nop
//IL_0009: ret
Method2(foo2);
//IL_0000: nop
//IL_0001: ldarga.s foo2
//IL_0003: ldc.i4.1
//IL_0004: call instance void ConsoleApp3.Foo2::set_I(int32)
//IL_0009: nop
//IL_000a: ret
Not a lot going on there
However, if you want to know what goes on the heap there is a bit more to the story
Memory usage in .NET when creating a new class or struct
A single reference either takes 4 bytes on 32-bit processes or 8 bytes
on 64-bit processes. A reference is a standard overhead on classes (as
they are reference types). Structs do not incur references (well,
ignoring any potential boxing) and are the size of their content
usually. I cannot remember if classes have any more overhead, don't
think so.
Does using “new” on a struct allocate it on the heap or stack?
Also as already pointed out, there are more considerations
Some more reading
Coding for performance: Struct vs Class
Even Further reading
Choosing Between Class and Struct
✓ CONSIDER defining a struct instead of a class if instances of the
type are small and commonly short-lived or are commonly embedded in
other objects.
More so
X AVOID defining a struct unless the type has all of the following
characteristics:
It logically represents a single value, similar to primitive types
(int, double, etc.).
It has an instance size under 16 bytes.
It is immutable.
It will not have to be boxed frequently.
In all other cases, you should define your types as classes.
Since your interested in performance, look at this as well
Writing Faster Managed Code: Know What Things Cost