I have little experience with Visual Basic.
I would like to add some methods to the System.Console class for a simple console application I am making. I am aware of the way to add extension methods to class. I’ve tried this code, but it gives the error: Reference to a non-shared member requires an object reference.
Imports System.Runtime.CompilerServices
Module Module1
<Extension()>
Public Sub WriteStuff(ByRef Console As System.Console, ByVal Output As String)
Console.Write(Output & "?")
End Sub
Sub Main()
Console.WriteStuff("Hello")
Console.ReadKey()
End Sub
End Module
Extension methods are instance methods; they cannot be applied statically.
System.Consoleis a class, not an object, and methods likeReadKey()are static. Static extension methods are not allowed.Look at your signature:
It makes no sense to take a class identifier by reference, right (or at all for that matter)?