VB.NET 不区分大小写;以及区分大小写? [英] VB.NET not case sensitive; well sort of case-sensitive?

查看:72
本文介绍了VB.NET 不区分大小写;以及区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在 C# 中没问题:

private int total;
public int Total {
    get {
        return total;
    }
}

因此,支持字段 total 的拼写与 Property Total 相同,唯一的区别是 Property Total代码>T.

So the backing field total is spelled the same as the Property Total with the only thing telling them apart being the case of the T.

使用 VB.NET VS 会抱怨我是否尝试执行以下操作.事实上,它甚至不会让我用小写的 t 编写 Return total 并自动更正为大写的 T

With VB.NET VS complains if I try to do the following. In fact it won't even let me write Return total with a lower case t and auto-corrects to an upper case T

但是如果我拼写支持字段不同,那么它似乎没问题:

But if I spell the backing field differently then it seems to be ok:

Private fTotal As Integer
Public ReadOnly Property Total() As Integer
    Get
        Return fTotal
    End Get
End Property

我意识到它们是不同的语言,但这种差异背后是否存在合乎逻辑的原因?(EDIT 最初说的是明显不一致"而不是差异")

I realize they are different languages but is there a logical reason behind this difference? (EDIT originally said "apparent inconsistency" rather than "difference")

另外 - 我假设即使 Visual Studio 自动更正我的 VB.NET 的大小写,但实际上这种语言不区分大小写?

Also - I assume even though Visual Studio auto-corrects the case of my VB.NET but in reality this language is not case-sensitive?

推荐答案

我意识到它们是不同的语言,但这种明显的不一致背后是否存在合乎逻辑的原因?

I realize they are different languages but is there a logical reason behind this apparent inconsistency?

最初的原因只是历史原因:VB 基于 BASIC,与当时的其他语言 (FORTRAN) 一样,它不区分大小写(但通常以全大写形式编写).

The original reason is simply historical: VB is based on BASIC which, like other languages at the time (FORTRAN) was case insensitive (but was usually written in all-uppercase).

此外,我没有看到任何不一致:在 VB 内部,大小写是完全一致的.特别是,它不像您的标题要求的那样区分大小写".

Furthermore, I don’t see any inconsistency: inside VB, the casing is entirely consistent. In particular, it’s not "sort of case-sensitive" as your title asks.

不区分大小写的逻辑原因,即使在今天也是如此:由于名称冲突,更难引入错误;考虑以下 C# 代码:

There is a logical reason to be case insensitive, even today: it makes it harder to introduce bugs due to name clashes; consider the following C# code:

private int total;

public int Total {
    get { return total; }
    set { Total = value; }
}

您是否立即发现了错误?如果是这样,还不错(这里的语法高亮有帮助).在 VB 中,此类错误不会发生.但在实践中,我认为这类错误并不是那么有问题,因为一旦发现它们很容易消除.因此,虽然这是不区分大小写的一个原因,但它并不是一个很强的原因.

Did you spot the error immediately? If so, not bad (the syntax highlight here helps). In VB, this class of errors cannot happen. But in practice I think this class of bugs isn’t all that problematic because once identified they are easily eliminated. So while this is a reason for case insensitivity, it’s not a very strong one.

最后,请注意 Windows 和 OS X 文件系统在此处使用与 VB 相同的约定:文件系统不区分大小写(文件名大小写无关紧要)但区分大小写——即文件系统保留文件名的原始大小写并正确显示,但在比较时不考虑大小写.

Finally, notice that Windows and OS X file systems use the same convention as VB here: the file system is case insensitive (filename case doesn’t matter) but case aware – meaning the file system preserves the original casing of a filename and displays it correctly but when comparing, it doesn’t consider case.

这篇关于VB.NET 不区分大小写;以及区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆