We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

VB.Net to C# Conversion Help

I am trying to convert the following VB.Net code to C# and I am getting the compiler error: VB.NET code: '' Create a delegate that will be called asynchronously Private Delegate Function GetTextData(ByVal DatabaseName As String, _ByVal ProcName As String) Dim async As New GetTextData(AddressOf TextProxy) Dim asyncResult As IAsyncResult My C# Conversion Code: // Create a delegate that will be called asynchronously private delegate void GetTextData(string DatabaseName, string ProcName); GetTextData async = new GetTextData(TextProxy); <-- Causes a compiler error IAsyncResult asyncResult; I am receiveing a compiler error of: A field initializer cannot reference the nonstatic field, method, or property ''Orgbrat.DataUtility.DBSchema.TextProxy(string, string)'' Can any of you other guys help me with this conversion. You help is much appreciated. Thanks... Steve Graddy orgbrat@orgbrat.com

1 Reply

SG Steve Graddy June 2, 2004 08:28 AM UTC

The answer to this was not a sysntax problem. I needed put the initializing code in the class constructor instead of putting them after the field declaration. // Create a delegate that will be called asynchronously private delegate void GetTextData(string DatabaseName, string ProcName); GetTextData async; IAsyncResult asyncResult; public MyClass { async = new GetTextData(TextProxy); } >I am trying to convert the following VB.Net code to C# and I am getting the compiler error: > > >VB.NET code: > '' Create a delegate that will be called asynchronously > Private Delegate Function GetTextData(ByVal DatabaseName As String, _ByVal ProcName As String) > > Dim async As New GetTextData(AddressOf TextProxy) > Dim asyncResult As IAsyncResult > >My C# Conversion Code: > // Create a delegate that will be called asynchronously > private delegate void GetTextData(string DatabaseName, string ProcName); > > GetTextData async = new GetTextData(TextProxy); <-- Causes a compiler error > IAsyncResult asyncResult; > >I am receiveing a compiler error of: > A field initializer cannot reference the nonstatic field, method, or property ''Orgbrat.DataUtility.DBSchema.TextProxy(string, string)'' > >Can any of you other guys help me with this conversion. You help is much appreciated. Thanks... > >Steve Graddy >orgbrat@orgbrat.com >

Loader.
Up arrow icon