CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Posts
    180

    How do I get around Inconsistant accessibilty error in C # ?

    How do I get around Inconsistant accessibilty error in C # ?

    I need to pass a pointer to a node in a linked list to a method.
    When I do, I get a "Compiler Error CS0051"

    Example
    The following sample generates CS0051:

    Copy Code
    // CS0051.cs
    public class A
    {
    // Try making B public since F is public
    // B is implicitly private here
    class B
    {
    }

    public static void F(B b) // CS0051
    {
    }

    public static void Main()
    {
    }
    }


    That is a simple example. The actual program is a bit more complicated. I am actually using a node in a linked list to pass to the method
    LinkedListNode<LevelNode> node

    The method uses recursion because the node is mart of a huge linked list structure of linked lists that outputs an xml file.
    Either I have to find a way to use recursion without using methods or I need to find a way to pass pointers nodes or actual nodes.

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: How do I get around Inconsistant accessibilty error in C # ?

    How do I get around Inconsistant accessibilty error in C # ?
    You make your classes consistently accessible. Really, there is nothing to get around, it is a bug in your code. You have a public class with a public method that returns an object of a class internal (it is not implicitly 'private', it is implicitly 'internal') to your assembly. How could that possibly work? How could code outside of your assembly possibly create an object of type 'B' when it does not have access to the definition or interface of said class? It can't. You need to think through your design a bit harder. Your interface for class 'A' defines a contract. It expects clients to work with an object of type 'B', but it doesn't want to tell them what a 'B' actually is.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured