Monday, December 28, 2009

ArraySegment<T> Class

Somehow I missed such a useful class in .Net framework this now. This class is useful when we are working on one dimensional arrays and need to segment arrays.

One quick use case is network packets. Where we will allocate buffer upfront and fill segments to form a packet.

Good part of this class is multiple arraysegment objects can refer to same instance of array. Mean what we get is reference to original object rather than a copy. Any updates to segment will automatically update original array.

Isn’t useful? I feel so.

1 comment:

Venkatesu Punugupati said...

I also don't know this till now.
Thanks Harsha at last i came to know from your blog.