开发者

Just realized IEnumerable<T> is immutable, what are other most commonly used immutable generic interfaces? MSDN doesn't say [closed]

开发者 https://www.devze.com 2023-04-03 07:00 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertis开发者_开发技巧e, but this question will likely so
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertis开发者_开发技巧e, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

Just realized IEnumerable is immutable, what are other commonly used immutable generic interfaces? MSDN doesn't say.

Or any good online resources?


Apart from the fact that it doesn't make a whole lot of sense to refer to interfaces as being immutable, IEnumerable<T> isn't, for example:

List<string> myList = new List<string>();
myList.Add("Test"); // We just changed the state of myList, hence its not immutable

An example of an object that is immutable is String.

It doesn't make sense for an interface to be immutable as almost by definition an immutable object needs to be sealed, which an interface obviously cannot be.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号