开发者

Assignment to apparently nonexistent variables in VB.NET

开发者 https://www.devze.com 2022-12-11 04:03 出处:网络
I have some VB.NET (which I don\'t normally deal with) code which must be converted to C# (which I normally do).

I have some VB.NET (which I don't normally deal with) code which must be converted to C# (which I normally do).

The code happens to be in a Windows Forms app. I notice a couple of places such 开发者_StackOverflowas:

Public Sub New()
    ParentWindow = Me

where there is no ParentWindow variable defined, and it doesn't seem to be inherited here:

Public Class MainWindow
    Inherits System.Windows.Forms.Form

    Private Shared parentWindow As MainWindow
    '....

(Though note that there is a similar variable with a lower-case first letter.)

and this:

DocumentCount = 0;

where, again, there is no corresponding variable definition and a straight conversion to C# Windows Forms indicates that there is no such member in the parent class.

Am I missing an import somewhere, or is this a feature peculiar to VB.NET that doesn't translate directly to C#?


If this is working it's likely that you have Option Explicit set to off. This is a feature of VB.Net that allows for variables to be used before they are declared. Try adding the following to the top of the file

Option Explicit On


VB is case insensitive, so it's actually assigning to parentWindow and documentCount.

(Edited in response to other comment)


VB is case insensitive. So parentWindow and ParentWindow may very well refer to the same variable. Usually the IDE fixes the case for you though...

0

精彩评论

暂无评论...
验证码 换一张
取 消