Very short C # function.
public static int SizeInBytes(this byte[] a) { return sizeof (int) + a.Length*sizeof (byte); }
What does the keyword "this" mean in this function? What is equivalent to this keyword in C ++? Also, what is this function trying to accurately calculate?
He marks the method as an extension method .
The extension method allows you to extend the functionality of any class, even if it is sealed.
Example:
public static class StringExtensions { public static bool IsEmpty (this string s) { return s == string.Empty; } }
, this.
++..... . ++ , ++, .
, #. ++.
, byte[], buffer, - (, ), :
byte[]
buffer
int buffSize = buffer.SizeInBytes();
- ( ), byte[] . , ++, , #.