Class VS ref Struct

后端 未结 2 1731
温柔的废话
温柔的废话 2021-02-09 01:15

I am programming a game using C#, thus, I am very concerned about performance.

I would like to know what are the main differences, and if possible, performance considera

2条回答
  •  滥情空心
    2021-02-09 01:51

    I know that a class is always passed by reference and that a struct is passed by value, but I talking about passing the struct by reference here.

    You probably have the right idea, but this is incorrect. Everything in C# is passed by value unless you use the ref keyword.

    Class instances are reference types, struct instances are value types.

    When you pass a reference type by value, you pass a copy of the reference (small). When you pass a value type by value, you pass a copy of the whole data (potentially large).

    Jon Skeet has a good explanation of all this here.

提交回复
热议问题