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 8170705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:12:50+00:00 2026-06-06T21:12:50+00:00

I have this below piece of code which makes me puzzling about internals of

  • 0

I have this below piece of code which makes me puzzling about internals of a private class. I could see many search results for this error, still the below sounds wierd

namespace X
{
    public class Program
    {
        public static XYZ sample1;
        public static void Main(string[] args)
        {
            XYZ sample2 = new XYZ(); // OK  (1)
            sample1 = new XYZ();  // NOK    (2)
                    ...
        }
    }

    private class XYZ
    {

    }
}

If class XYZ is private, how does it work at (1) but not in (2)?

  • 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-06-06T21:12:53+00:00Added an answer on June 6, 2026 at 9:12 pm

    It works in both (1) and (2):

    // OK, you declare and assign a local variable of a known type
    XYZ sample2 = new XYZ();
    
    // OK, you assign a static field of a known type
    sample1 = new XYZ();
    

    You can’t declare public static XYZ sample1; at all because it’s public when XYZ is private:

    // This won't compile if XYZ is private
    public static XYZ sample1;
    

    This makes sense, users of X.Program will have access to its public members (in this case sample1) but they won’t be able to use them because XYZ is private to the assembly (then not accessible). That’s why the compiler says “inconsistent accessibility”.

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

Sidebar

Related Questions

I have this code below. I need to use a class id instead of
I have this code below. As you can see I am passing two variables
I have class like this below shown. which contains the shopping items where the
I have a piece of ada code shown below which is a simple switch
I have this piece of code which i am using on another area of
I have this piece of code which works, however I would like to change
I have a piece of code below which I am trying to use to
I have this piece of code which plays my mp3 files on my iphone
I have the below piece of code which Prefixs a string to the start
I have a piece of code below which works fine when it comes to

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.