Answer the question
In order to leave comments, you need to log in
Does a reference field in a C# structure affect anything?
For example:
struct MyStruct
{
int id;
MyClass myClass;
}
Answer the question
In order to leave comments, you need to log in
Do as the situation demands. There are no restrictions.
Perhaps there will be some inconvenience when saving to the database or serialization, but again it depends on the situation and there are a lot of solutions to get rid of these inconveniences.
You need to be careful when copying them.
In your case, the myClass field stores a reference to a memory area on the heap. Copying a value type( which is what a struct refers to) just creates a new value on the stack.
var a = 0;
var b = a; //на стек помещается значение 0. Число есть число, ни на что не ссылается
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question