Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 114825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:55:20+00:00 2026-05-11T02:55:20+00:00

I was refactoring some code, and part of it included moving it from VB.Net

  • 0

I was refactoring some code, and part of it included moving it from VB.Net to C#.

The old code declared a member like this:

Protected viewMode As New WebControl 

The new code, I eventually got working, like this:

protected WebControl _viewMode = new WebControl(HtmlTextWriterTag.Span); 

I can presume that the New keyword meant: call the constructor! But how was VB.Net calling a constructor (a parameter-less one) that I couldn’t call in C#?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:55:20+00:00Added an answer on May 11, 2026 at 2:55 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm refactoring some code that currently looks like this: $$('#wrapper > div').each(function(e){ if((e.id!='header') &&
I'm refactoring some piece of... code, part of huge, complex .Net project. There is
I'm refactoring some code I inherited from a long-gone developer, and I find this:
Refactoring some code again. Seeing some of this in one of the ASP.NET pages:
I'm in the midst of some refactoring some C# code and part of this
I am refactoring some code for a Ruby library. This code includes a Date
I am refactoring some code to decouple GUI from some state. #include <StateObject> Class
While refactoring some code, I came across this strange compile error: The constructor call
Doing some refactoring in some legacy code I've found in a project. This is
I was refactoring some old code (by other people) and I came across the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.