I have a question related to passing parameters byRef, I have a library of classes based on VB.NET in which some functions are defined using argument types byref. These parameters are objects of the parent class, and when I tried to call this function and pass the object of the child class in the byref argument, it works in VB.NET, but I cannot do the same in C #
the next one is the test code I'm trying
Public Class Father Private _Cast As String Public Property Cast() As String Get Return _Cast End Get Set(ByVal value As String) _Cast = value End Set End Property End Class Public Class Son Inherits Father Private _MyName As String Public Property Myname() As String Get Return _MyName End Get Set(ByVal value As String) _MyName = value End Set End Property End Class
VB implementation class
Public Class Parent Public Function Show(ByRef value As Father) As Boolean Dim test As String = value.Cast Return True End Function
// Herer I can call the Show method and pass the child into an argument of type ByRef, and it works
Public Function Show2() As Boolean Dim s As New Son Dim result As Boolean = Show(s) Return True End Function End Class
// But when I try to do the same in C #
Parent p = new Parent(); Son s = new Son(); Father f = new Father(); p.Show(ref s);
I get an error that the Son cannot convert to a father, I am already testing it in VB, but how can I get it to work in C #? since I have a class library in dll format
Thank you in advance
source share