Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

class design - In C#, use of value types vs. reference types

My questions are:

  • When should we use value types and when reference types?
  • What are the advantages and disadvantages of one over other?
  • What if one uses reference types everywhere? Is there any harm in it?

Please also discuss advantages and disadvantages of each one. I want to understand that as well.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should use value types for small, immutable types which represent values.
Never make mutable structs.

For everything else, use reference types.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...