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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:03:44+00:00 2026-05-14T20:03:44+00:00

I have 2 scenarios. This fails: class F<X> { public X X { get;

  • 0

I have 2 scenarios.

This fails:

class F<X>
{
  public X X { get; set; }
}

error CS0102: The type ‘F<X>‘ already contains a definition for ‘X‘

This works:

class F<X>
{
  class G
  {
    public X X { get; set; }
  }
}

The only logical explanation is that in the second snippet the type parameter X is out of scope, which is not true…

Why should a type parameter affect my definitions in a type?

IMO, for consistency, either both should work or neither should work.

Any other ideas?

PS: I call it ‘lexical’, but it is probably not the correct term.

Update:

As per Henk’s answer, here is a non-generic version displaying the same behavior, but perhaps easier to grok.

Fails:

class F
{
  class X { }
  public X X { get; set; }
}

Works:

class X { }
class F
{
  public X X { get; set; }
}

From what I can see, the C# compiler creates a lexical scope at type definition boundries.

It also implies that types and member names live in the same ‘location’ (or namespace in terms of LISP).

  • 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-14T20:03:44+00:00Added an answer on May 14, 2026 at 8:03 pm

    The class G introduces a distinctive naming scope. If you omit the default rules, the 2 versions become:

    public F<X>.X F<X>.X { get; set; }    // error
    public F<X>.X F<X>.G.X { get; set; }  // OK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that acts like this at the moment: public class MyClass
I have an class which should send/receive data in packet form. This class contains
we have this scenario: A server which contains needed data and client component which
Please Consider this scenario: We have a base class called clsMain : class clsMain
I have a DependencyObject class composition that looks like the following: public class A
Help! This code works fine on my local VS2010 with TypeMock, however fails on
I have this scenario where I need data integrity in the physical database. For
I have this scenario. I want group on Country and Category. A store can
I have this scenario where I would like to redirect my domains using the
I have a scenario like this: form = MockRepository.GenerateMock<IAddAddressForm>(); mediator = new AddAddressMediator(form); 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.