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

Ask A Question

Stats

  • Questions 174k
  • Answers 174k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer @interface CarClass : NSObject { EngineClass *engine; NSArray *tires; }… May 12, 2026 at 2:54 pm
  • Editorial Team
    Editorial Team added an answer In your controller class AccountController < ApplicationController after_filter :populate_db :only=>[:register]… May 12, 2026 at 2:54 pm
  • Editorial Team
    Editorial Team added an answer There is a specification for the parameters (salt and iterations)… May 12, 2026 at 2:54 pm

Related Questions

I've been tinkering with small functions on my own time, trying to find ways
Let's say that you have to implement some functionality that is not trivial (it
Question My question is how can you teach the methods and importance of tidying-up
In my copious free time, I collaborate with a number of scientists (mostly biologists)

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.