VB真的不区分大小写吗? [英] Is VB really case insensitive?

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

问题描述

我不是要在这里开始争论,但是无论出于何种原因,通常都说Visual Basic不区分大小写,而C语言则不(这在某种程度上是件好事)。

I'm not trying to start an argument here, but for whatever reason, it's typically stated that Visual Basic is case insensitive and C languages aren't (and somehow that is a good thing).

但这是我的问题:Visual Basic的大小写到底在哪里不敏感?当我键入...

But here's my question: Where exactly is Visual Basic case insensitive? When I type...

Dim ss As String
Dim SS As String

...进入 Visual Studio 2008 Visual Studio 2010 IDE,第二个警告是 在当前块中已经声明了局部变量 SS 。在VBA VBE中,它不会立即引发错误,而是会自动更正大小写。

...into the Visual Studio 2008 or Visual Studio 2010 IDE, the second one has a warning of "Local variable SS is already declared in the current block". In the VBA VBE, it doesn't immediately kick an error, but rather just auto-corrects the case.

我在这里缺少Visual Basic是不区分大小写? (此外,如果您知道或愿意回答,那为什么会是一件坏事?)

Am I missing something here with this argument that Visual Basic is not case sensitive? (Also, if you know or care to answer, why would that be a bad thing?)

我为什么还要问这个问题?

Why am I even asking this question?

多年来,我已经在其许多
方言中使用了Visual Basic,有时是
a爱好者,有时
工作组中的小型
与业务相关的程序。过去六个月来,我一直在从事
的大型项目,比我预期的要大得多。
中的大部分示例源代码都在C#中。我没有强烈的
学习C#的欲望,但如果有
的东西,我在C#上就错过了
提供的Visual Basic没有的东西(与之相反的
是VB.NET提供的 XML文字),那么我想知道
关于该功能的更多信息。因此,在这种
情况下,经常有人争辩说C
语言区分大小写,而
很好,而Visual Basic对
不区分大小写,这是不好的。我想让
知道...

I've used Visual Basic in many of its dialects for years now, sometimes as a hobbyist, sometimes for small business-related programs in a workgroup. As of the last six months, I've been working on a big project, much bigger than I anticipated. Much of the sample source code out there is in C#. I don't have any burning desire to learn C#, but if there are things I'm missing out on that C# offers that Visual Basic doesn't (an opposite would be VB.NET offers XML Literals), then I'd like to know more about that feature. So in this case, it's often argued that C languages are case sensitive and that's good and Visual Basic is case insensitive and that is bad. I'd like to know...


  1. 自从每个$ b以来,Visual Basic
    大小写到底如何不敏感?
    在代码编辑器中的单个示例
    变得区分大小写(意味着
    的情况得到纠正),无论我是否想要

  2. 这是吗?对我来说足够引人注目的
    考虑如果VB.NET案例
    以某种方式限制了我可以用代码执行
    的事情,请考虑使用C#?


推荐答案

VBA与 VB.NET 仅仅是因为VB.NET在后台连续编译。

The difference between VBA and VB.NET is just because VB.NET compiles continuously in the background. You'll get an error when you compile the VBA.

就像 Jonathan说,在编程时,除了字符串比较,XML和其他一些情况外,您还可以将VB.NET视为不区分大小写。

Like Jonathan says, when programming you can think of VB.NET as case-insensitive apart from string-comparisons, XML, and a few other situations...

我认为您对引擎盖下的内容感兴趣。嗯.NET公共语言运行时区分大小写,并且VB.NET代码依赖于运行时,因此您可以看到它在运行时必须区分大小写,例如

I think you're interested in what's under the hood. Well, the .NET Common Language Runtime is case-sensitive, and VB.NET code relies on the runtime, so you can see it must be case-sensitive at runtime, e.g. when it's looking up variables and methods.

VB.NET编译器和编辑器可让您忽略它-因为它们在代码中更正了大小写

The VB.NET compiler and editor let you ignore that - because they correct the case in your code.

如果您使用动态功能或后期绑定(Option Strict Off),则可以证明基本运行时区分大小写。另一种查看方式是认识到区分大小写的语言(例如C#)使用相同的运行时,因此运行时显然支持区分大小写。

If you play around with dynamic features or late-binding (Option Strict Off) you can prove that the underlying run-time is case-sensitive. Another way to see that is to realise that case-sensitive languages like C# use the same runtime, so the runtime obviously supports case-sensitivity.

EDIT 如果您想排除IDE,可以始终从命令行编译。在记事本中编辑代码,使其具有 ss 和 SS 并查看编译器的作用。

EDIT If you want to take the IDE out of the equation, you can always compile from the command-line. Edit your code in Notepad so it has ss and SS and see what the compiler does.

编辑引用 Jeffrey Richter 。 stackoverflow.com/amzn/click/0321545613 rel = noreferrer>。NET Framework设计指南第45页。

EDIT Quote from Jeffrey Richter in the .NET Framework Design Guidelines page 45.


需要明确的是,CLR实际上是区分大小写的
。某些编程
语言(例如Visual Basic)对大小写
不敏感。当Visual Basic编译器是
试图解决对区分大小写
语言(如C#)定义的
类型的方法调用时,编译器(不是CLR的
)会指出方法名称的实际情况
并将其嵌入
元数据中。 CLR对此一无所知。现在,如果您使用反射
绑定到方法,则反射
API确实可以执行
不区分大小写的查找。这是CLR提供
不区分大小写的
程度。

To be clear, the CLR is actually case-sensitive. Some programming languages, like Visual Basic, are case insensitive. When the Visual Basic compiler is trying to resolve a method call to a type defined in a case-sensitive language like C#, the compiler (not the CLR) figures out the actual case of the method's name and embeds it in metadata. The CLR knows nothing about this. Now if you are using reflection to bind to a method, the reflection APIs do offer the ability to do case-insensitive lookups. This is the extent to which the CLR offers case-insensitivity.

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

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