1

According to the documenation on MSDN, IPEndPoint can have its Address and Port properties set.

Why was this class designed to be mutable? It seems like it should be immutable for the same reasons that classes such as String are.

Is there an immutable version of this class that is more appropriate for passing around threads, event-handlers and so on?

Community
  • 1
  • 1
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
  • If you need an immutable version, just build it. If you pass an instance to whatever, you always have to decide if you are interested in the instance itself or just the values/state it represents. If you only need the values/state you can store a copy of them. If the postman brings you a letter, you only take the letter and not the postman - although you can remember who was it. And if you read the letter you did not put the letter in your head but the meaning of the written words -> a copy – Sir Rufo Sep 05 '15 at 09:04

1 Answers1

6

There is no immutable version of that class built-in.


Subjective part of answer: Making this class mutable is a design flaw in the .NET Framework. 15 years ago when it was created it was not well known that immutability often makes API design better. The BCL has quite a few places of mutability that should not be there.

usr
  • 168,620
  • 35
  • 240
  • 369