Saturday, September 15, 2018

C# span vs. GoLang slice

Span in .NET, C# and other languages | Tudor Turcu – blog


var arr = new byte[10];
var slice = new Span(arr, 5, 2);

var arr [10]int
var slice = arr[5:7]

"In both languages, a span(C#) or a slice (Go) represent a similar concept:
  • C#: ‘Span is a value type containing a ref and a length‘ , ‘represent contiguous regions of arbitrary memory‘
  • Go: ‘Slice is a descriptor for a contiguous segment of an underlying array and provides access to a numbered sequence of elements from that array‘"

No comments: