I can do this in VB.NET
Module ArrayExtension
<Runtime.CompilerServices.Extension()>
Public Sub Add(Of T)(ByRef arr As T(), item As T)
If arr IsNot Nothing Then
Array.Resize(arr, arr.Length + 1)
arr(arr.Length - 1) = item
Else
ReDim arr(0)
arr(0) = item
End If
End Sub
End Module
And NOT do this in C#
using System;
internal static class ArrayExtension
{
public static void Add<T>(this ref T[] arr, T item)
{
if (arr != null)
{
Array.Resize(ref arr, arr.Length + 1);
arr[arr.Length - 1] = item;
}
else
{
arr = new T[1];
arr[0] = item;
}
}
}
In VB it works fine, I can use the extension without problems, but in C# "this" doesn't go with "ref". I've read other questions concerning extensions in C#, but my question is, how does it work in VB.NET? Since they belong to the same framework, that should be no problem... Is the "<Runtime.CompilerServices.Extension()>" directive the case? Thank you.