简体   繁体   English

ASP.NET C#到VB的转换

[英]ASP.NET C# to VB conversion

I have a Web Application that I'm trying to update. 我有一个要更新的Web应用程序。 I am required to code using Visual Basic, yet the old version has some C# code that's giving me a hard time to translate into VB. 我需要使用Visual Basic进行编码,但是旧版本具有一些C#代码,这使我很难转换成VB。 I'd appreciate any help you can give me thanks. 多谢您能给予我的帮助。 :) :)

clsSeguridad oseg = new clsSeguridad();
oseg.DatosLogin += new EventHandler<clsSeguridad.DatosLoginEventArgs>(oseg_DatosLogin);

The first line is easy to translate. 第一行很容易翻译。 Basically, this is what's going on: cslSeguridad is a custom class that contains many methods to validate a user Login. 基本上,这是正在发生的事情:cslSeguridad是一个自定义类,其中包含许多用于验证用户登录的方法。 In order to login, you must first create the object and then add the EventHandler that will be invoked later on in the method. 为了登录,必须首先创建对象,然后添加稍后将在方法中调用的EventHandler。 That's the problem for me... I can't seem to be able to add a new Handler... Visual Studio suggests that I use a RaiseEvent, yet I am unsure that that's what I am supposed to do since I didn't write up the original code. 那是我的问题...我似乎无法添加新的处理程序... Visual Studio建议我使用RaiseEvent,但是我不确定那是我应该做的,因为我没有写下原始代码。 Thanks in advance for the help. 先谢谢您的帮助。

In VB.NET, you would use: 在VB.NET中,您将使用:

AddHandler oseg.DatosLogin, New EventHandler(Of clsSeguridad.DatosLoginEventArgs)(oseg_DatosLogin)

The AddHandler statement is used to attach a function or subroutine to an event. AddHandler语句用于将函数或子例程附加到事件。

For future reference, you can use one of the numerous online tools available to convert code between C# and VB. 为了将来参考,您可以使用众多可用的在线工具之一在C#和VB之间转换代码。 Matt Wilko suggests http://www.carlosag.net/Tools/CodeTranslator/ 马特·威尔科(Matt Wilko)建议http://www.carlosag.net/Tools/CodeTranslator/

I have been know to use .Net reflector to translate code between C# and VB. 我知道使用.Net反射器在C#和VB之间转换代码。 You can also pick Delphi, F#, IL C++ and Oxygene as language targets. 您还可以选择Delphi,F#,IL C ++和Oxygene作为语言目标。 If you are using a debug assembly, the disassembled code snippets are usually pretty close to what you would write by hand. 如果使用调试程序集,则反汇编的代码段通常与您手工编写的代码段非常接近。

There are two ways 有两种方法

1 . 1。 Hard coded handling 硬编码处理

declare your class member _member WithEvents and later declate a method as 声明您的类成员_member WithEvents ,然后将方法声明为

`private sub MySub() Handles _member.Event`

2 . 2。 More dynamic way 更动态的方式

Somewhere in code use 在代码中使用的某个地方

AddHandler _member.Event, addressOf (handling_sub)

Don't forget to use RemoveHandler or ... memory leaks 不要忘了使用RemoveHandler或...内存泄漏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM