private struct

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark

    #1

    private struct

    I have a .cs file that contains a public class and a public struct in a
    single namespace. I decided I wanted the struct to only be accessible to
    the class, and not to the rest of my project. I changed the public struct
    to a private struct, but it gave me the following error ... why? What are
    my options? Thanks in advance! - Mark

    "Namespace elements cannot be explicitly declared as private, protected, or
    protected internal."


  • William Stacey

    #2
    Re: private struct

    If you want it internal to the class only, then nest it inside the class and
    make it private (e.g. nested class/struct). If you want it internal to your
    namespace, put it in your namespace and make it internal.

    --
    William Stacey, DNS MVP

    "Mark" <field027_nospa m_@umn.edu> wrote in message
    news:eAOfcw1cDH A.2960@tk2msftn gp13.phx.gbl...[color=blue]
    > I have a .cs file that contains a public class and a public struct in a
    > single namespace. I decided I wanted the struct to only be accessible to
    > the class, and not to the rest of my project. I changed the public struct
    > to a private struct, but it gave me the following error ... why? What are
    > my options? Thanks in advance! - Mark
    >
    > "Namespace elements cannot be explicitly declared as private, protected,[/color]
    or[color=blue]
    > protected internal."
    >
    >[/color]


    Comment

    • Jasper Kent

      #3
      Re: private struct

      Sorry to disagree, but a class cannot be internal to a namespace, only too
      an assembly.

      Regards,

      Jasper Kent.

      "William Stacey" <staceyw@mvps.o rg> wrote in message
      news:%23IM9C21c DHA.2404@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > If you want it internal to the class only, then nest it inside the class[/color]
      and[color=blue]
      > make it private (e.g. nested class/struct). If you want it internal to[/color]
      your[color=blue]
      > namespace, put it in your namespace and make it internal.
      >
      > --
      > William Stacey, DNS MVP
      >
      > "Mark" <field027_nospa m_@umn.edu> wrote in message
      > news:eAOfcw1cDH A.2960@tk2msftn gp13.phx.gbl...[color=green]
      > > I have a .cs file that contains a public class and a public struct in a
      > > single namespace. I decided I wanted the struct to only be accessible[/color][/color]
      to[color=blue][color=green]
      > > the class, and not to the rest of my project. I changed the public[/color][/color]
      struct[color=blue][color=green]
      > > to a private struct, but it gave me the following error ... why? What[/color][/color]
      are[color=blue][color=green]
      > > my options? Thanks in advance! - Mark
      > >
      > > "Namespace elements cannot be explicitly declared as private, protected,[/color]
      > or[color=green]
      > > protected internal."
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • William Stacey

        #4
        Re: private struct

        Sorry Jasper, that is what I meant. Put it in the namespace and make it
        internal - which will make it internal to the assembly. I assumed his
        namespace was the only one in the assembly as he noted a single namespace.

        --
        William Stacey, DNS MVP

        "Jasper Kent" <jasper_kent@ho tmail.com> wrote in message
        news:#DOT225cDH A.2460@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Sorry to disagree, but a class cannot be internal to a namespace, only too
        > an assembly.
        >
        > Regards,
        >
        > Jasper Kent.
        >
        > "William Stacey" <staceyw@mvps.o rg> wrote in message
        > news:%23IM9C21c DHA.2404@TK2MSF TNGP10.phx.gbl. ..[color=green]
        > > If you want it internal to the class only, then nest it inside the class[/color]
        > and[color=green]
        > > make it private (e.g. nested class/struct). If you want it internal to[/color]
        > your[color=green]
        > > namespace, put it in your namespace and make it internal.
        > >
        > > --
        > > William Stacey, DNS MVP
        > >
        > > "Mark" <field027_nospa m_@umn.edu> wrote in message
        > > news:eAOfcw1cDH A.2960@tk2msftn gp13.phx.gbl...[color=darkred]
        > > > I have a .cs file that contains a public class and a public struct in[/color][/color][/color]
        a[color=blue][color=green][color=darkred]
        > > > single namespace. I decided I wanted the struct to only be accessible[/color][/color]
        > to[color=green][color=darkred]
        > > > the class, and not to the rest of my project. I changed the public[/color][/color]
        > struct[color=green][color=darkred]
        > > > to a private struct, but it gave me the following error ... why? What[/color][/color]
        > are[color=green][color=darkred]
        > > > my options? Thanks in advance! - Mark
        > > >
        > > > "Namespace elements cannot be explicitly declared as private,[/color][/color][/color]
        protected,[color=blue][color=green]
        > > or[color=darkred]
        > > > protected internal."
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...