c#-to-vb.net

Converting C# knowledge to VB.NET any potential problems?

允我心安 提交于 2019-11-28 01:52:17
I have a team with people that are quite comfortable in C# but we got a requirement to write a project in VB.net. How hard would it be to think in C# and on the fly convert to VB? Is that doable? Could you list the issues that we can come across? I heard that VB.net doesn't have closures. Is that still true for .net 3.5? If you are approaching VB.Net with the mindset of C# it's best to set the following options in the project Option Strict On Option Explicit On Option Infer On This essentially removes the late binding semantics of VB.Net and forces it to be a strictly typed language. This will

What is the VB.NET equivalent of the C# “is” keyword?

此生再无相见时 提交于 2019-11-27 21:30:54
问题 I need to check if a given object implements an interface. In C# I would simply say: if (x is IFoo) { } Is using a TryCast() and then checking for Nothing the best way? 回答1: Try the following if TypeOf x Is IFoo Then ... 回答2: Like this: If TypeOf x Is IFoo Then 回答3: The direct translation is: If TypeOf x Is IFoo Then ... End If But (to answer your second question) if the original code was better written as var y = x as IFoo; if (y != null) { ... something referencing y rather than (IFoo)x ...

Can VB.NET be forced to initialize instance variables BEFORE invoking the base type constructor?

风流意气都作罢 提交于 2019-11-27 20:27:41
After debugging a particularly tricky issue in VB.NET involving the order in which instance variables are initialized, I discovered that there is a breaking discrepancy between the behavior that I expected from C# and the actual behavior in VB.NET. Nota bene: This question concerns a slight discrepancy in the behaviors of VB.NET and C#. If you're a language bigot that is unable to provide an answer other than "that's why you should use C#, noob" , there is nothing for you to see here; kindly move along. Specifically, I expected the behavior outlined by the C# Language Specification (emphasis

Is there a VB.NET equivalent of C# out parameters?

无人久伴 提交于 2019-11-27 08:10:00
Does VB.NET have a direct equivalent to C# out function parameters, where the variable passed into a function does not need to be initialised? No, there is no equivalent of the out keyword in VB. However, VB does automatically initialise all local variables in a method, so you can use ByRef without needing to explicitly initialise the variable first. Example: Sub Main() Dim y As Integer Test(y) End Sub Sub Test(ByRef x As Integer) x = 42 End Sub (If you examine code in the framework (for example Double.TryParse ), you may see the <OutAttribute> added to parameters, but that only makes a

Syntax for adding an event handler in VB.NET

Deadly 提交于 2019-11-27 06:44:27
问题 I have following code i need to convert to VB.NET. Problem is every translation tool I found is converting the add handler part wrong. I don't seem to be able to do it by myself. FtpClient ftpClient = new FtpClient(); ftpClient.UploadProgressChanged += new EventHandler<UploadProgressChangedLibArgs>(ftpClient_UploadProgressChanged); ftpClient.UploadFileCompleted += new EventHandler<UploadFileCompletedEventLibArgs>(ftpClient_UploadFileCompleted); 回答1: There are two different ways to associate

Converting C# knowledge to VB.NET any potential problems?

你。 提交于 2019-11-26 22:04:21
问题 I have a team with people that are quite comfortable in C# but we got a requirement to write a project in VB.net. How hard would it be to think in C# and on the fly convert to VB? Is that doable? Could you list the issues that we can come across? I heard that VB.net doesn't have closures. Is that still true for .net 3.5? 回答1: If you are approaching VB.Net with the mindset of C# it's best to set the following options in the project Option Strict On Option Explicit On Option Infer On This