本文介绍了什么是在Visual Basic中允许的在C#中(反之亦然)禁止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是的 code相关在什么样的编译器可以让你用一种语言做的,而不是让你用另一种语言做(如VB可选参数不存在于C#)。

This is code-related as in what the compiler will allow you to do in one language, but not allow you to do in another language (e.g. optional parameters in VB don't exist in C#).

请提供一个code例如你的回答,如果可能的话。谢谢!

Please provide a code example with your answer, if possible. Thank you!

推荐答案

VB和C#有一个什么样的保护意味着不同的跨pretations。

VB and C# have different interpretations of what "protected" means.

Here's解释的复制如下:

有关WebControl的默认构造函数
  被保护。

VB和C#有不同
  什么保护国米pretations
  意思。

VB and C# have different interpretations of what "protected" means.

在VB中,您可以访问受保护
  在任何方法的类的成员
  任何类型从类派生。

In VB, you can access a protected member of a class from any method in any type that derives from the class.

也就是说,VB允许这种code到
  编译:

That is, VB allows this code to compile:

class Base
    protected m_x as integer
end class

class Derived1
    inherits Base
    public sub Foo(other as Base)
        other.m_x = 2
    end sub
end class

class Derived2
    inherits Base
end class

由于一个Derived1是碱,它可以
  访问受保护的其他的成员,
  这也是一个基础。

Because a "Derived1" is a base, it can access protected members of "other", which is also a base.

C#采取了不同的观点。它
  不允许杯酒人生获得
  保证VB。它说,访问
  保护成员可以通过进行
  这个或任何相同类型的对象
  作为包含该方法的类

C# takes a different point of view. It doesn't allow the "sideways" access that VB does. It says that access to protected members can be made via "this" or any object of the same type as the class that contains the method.

由于富在这里被定义
  Derived1,C#将只允许富
  访问从基地组织成员
  Derived1实例。这是可能的
  其他是东西是不是
  Derived1(它可能,例如,是
  一个Derived2的),并且因此它不会
  允许访问m_x。

Because "Foo" here is defined in "Derived1", C# will only allows "Foo" to access "Base" members from a "Derived1" instance. It's possible for "other" to be something that is not a "Derived1" (it could, for example, be a "Derived2"), and so it does not allow access to "m_x".

这篇关于什么是在Visual Basic中允许的在C#中(反之亦然)禁止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 14:14