Results 1 to 3 of 3

Thread: VB.NET and C#

  1. #1
    numan007 is offline Senior Member+
    Last Online
    9th March 2014 @ 01:05 PM
    Join Date
    22 Sep 2008
    Age
    32
    Posts
    140
    Threads
    30
    Credits
    0
    Thanked: 1

    Default VB.NET and C#

    VB2008,VB.NET and C# yar koi in tamam languages me fark bata day jaldi say.............

  2. #2
    sajjad shah is offline Senior Member+
    Last Online
    1st March 2016 @ 04:37 PM
    Join Date
    09 Feb 2007
    Location
    Rawalpindi
    Age
    37
    Gender
    Male
    Posts
    1,897
    Threads
    90
    Credits
    0
    Thanked
    2

  3. #3
    sajjad shah is offline Senior Member+
    Last Online
    1st March 2016 @ 04:37 PM
    Join Date
    09 Feb 2007
    Location
    Rawalpindi
    Age
    37
    Gender
    Male
    Posts
    1,897
    Threads
    90
    Credits
    0
    Thanked
    2

    Default

    The reason this worked in VB, and not in C#, had nothing to do with assemblies.

    The default constructor for WebControl is protected.

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

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

    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

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

    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.

    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".

    In this case of your code, VB allowed "sideways" access to the "WebControl" constructor.

    C#, however, did not.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •