How to avoid the boxing during the value type parameter passing in .NET?
Is the use of the ref
keyword is the only way? E.g. in this way:
using System;
namespace myprogram
{
struct A {
public static void foo(ref A a) {}
}
class Program {
static void Main(string[] args) {
A a = new A();
A.foo(ref a);
}
}
}
Or are there any other ways to accomplish this?
I found this answer. It explains what operations should I avoid in order to avoid boxing, but it does not tell how I can do that.
Also, I am reading the CLR via C# book which also misses the point of how to pass the value type without boxing (or at least after reading the book I did not find the information).