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

  • Home
  • SEARCH
  • 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 870501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:29:14+00:00 2026-05-15T10:29:14+00:00

I`m just started learning C#, used to be a VB programmer. In VB.NET, it

  • 0

I`m just started learning C#, used to be a VB programmer.

In VB.NET, it is possible to access a form class method, even if this method is not declared as shared.
In the code below, I don`t get compiler errors, and calling the method Foo inside ClassFoo works ok.

Public Class Form1
    Public Sub Foo()
        MsgBox("Test")
    End Sub
End Class

Public Class ClassFoo
    Sub Foo()
        Form1.Foo()
    End Sub
End Class

Then, I tried to port the same code to C#, but I get an error:
“An object reference is required for non-static field and bla bla bla”.

Why I can access a method not shared in VB and can`t in C#?

  • 1 1 Answer
  • 0 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. Editorial Team
    Editorial Team
    2026-05-15T10:29:15+00:00Added an answer on May 15, 2026 at 10:29 am

    This is a rather horrific feature inherited from VB6, a language that allowed this construct. It is not allowed in a pure OOP language, referencing a member of an object requires an object name, not a type name.

    The VB.NET team went through some trouble to make this work in the VB.NET language. “Form1” in this statement is in fact an object reference, one that gets auto-generated by the compiler. Something that goes horribly wrong when that name is used in threads btw.

    But this won’t fly in the C# language, you have to supply an object reference. You will have to re-factor the code so the ClassFoo object has that reference. Something like this:

    public class Form1 {
        ClassFoo fooObj;
        public Form1() {
            fooObj = new ClassFoo(this);
        }
        public void Foo() {
            MessageBox.Show("un-fooed");
        }
    }
    
    public class ClassFoo {
        Form1 mainForm;
        public ClassFoo(Form1 main) {
            mainForm = main;
        }
        public void Foo() {
            mainForm.Foo();
        }
    }
    

    This is probably going to cause some pain while you are learning C#. The Q&D workaround for this is to use Application.OpenForms. Avoid using it if you prefer to byte the bullet.

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

Sidebar

Related Questions

I just started learning ASP.NET MVC4 today. After reading tutorials, downloading VS 2012, and
I just started learning C but I don't understand this part of the code.
I'm familiar with C++ but never used Java. I've just started learning Android development.
Just started learning PySide and is having problem with QTimer I have this #!/usr/bin/python
I have just started learning XNA. This is my first program that I am
I have just started learning asp.net mvc and one reason of the primary reasons
I just started learning C++ and I wrote this sample program from the text
Just started learning Haskell. I have an empty source file with this inside: pe
So I just started learning haskell and I'm trying to use this if statement:
Very confused over this. I've just started learning about pointers and have now decided

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.