namespace not found

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

    namespace not found

    I am setting a string collection as:

    Specialized.Str ingCollection s1

    But I get an error saying

    namespace name 'Specialized' not found.

    System.Collecti ons.Specialized .StringCollecti on s1 does work.

    But I do have:

    using System.Collecti ons;

    Why doesn't the program recognize this and force me to put the whole
    namespace in?

    Thanks,

    Tom


  • Jeroen Mostert

    #2
    Re: namespace not found

    tshad wrote:
    I am setting a string collection as:
    >
    Specialized.Str ingCollection s1
    >
    But I get an error saying
    >
    namespace name 'Specialized' not found.
    >
    System.Collecti ons.Specialized .StringCollecti on s1 does work.
    >
    But I do have:
    >
    using System.Collecti ons;
    >
    Why doesn't the program recognize this and force me to put the whole
    namespace in?
    >
    Because namespaces do not work that way. Or rather, using directives do not
    work that way. Namespaces must always be referred to by their full name.
    This arguably prevents some readability issues, because it saves you from
    wondering whether "Specialize d" is a namespace or a class in
    System.Collecti ons (with StringCollectio n as a nested class).

    If you want a shorthand, then use either

    using System.Collecti ons.Specialized ;

    or

    using StringCollectio n = System.Collecti ons.Specialized .StringCollecti on;

    The former imports the whole namespace and the latter just the class (this
    is also the syntax to use for assigning aliases). In Visual Studio, you can
    right-click any unresolved class name and choose "Resolve" to automatically
    add the appropriate import.

    --
    J.

    Comment

    • tshad

      #3
      Re: namespace not found

      Great thanks,

      Tom

      "Jeroen Mostert" <jmostert@xs4al l.nlwrote in message
      news:4877eda0$0 $14346$e4fe514c @news.xs4all.nl ...
      tshad wrote:
      >I am setting a string collection as:
      >>
      >Specialized.St ringCollection s1
      >>
      >But I get an error saying
      >>
      >namespace name 'Specialized' not found.
      >>
      >System.Collect ions.Specialize d.StringCollect ion s1 does work.
      >>
      >But I do have:
      >>
      >using System.Collecti ons;
      >>
      >Why doesn't the program recognize this and force me to put the whole
      >namespace in?
      >>
      Because namespaces do not work that way. Or rather, using directives do
      not work that way. Namespaces must always be referred to by their full
      name. This arguably prevents some readability issues, because it saves you
      from wondering whether "Specialize d" is a namespace or a class in
      System.Collecti ons (with StringCollectio n as a nested class).
      >
      If you want a shorthand, then use either
      >
      using System.Collecti ons.Specialized ;
      >
      or
      >
      using StringCollectio n =
      System.Collecti ons.Specialized .StringCollecti on;
      >
      The former imports the whole namespace and the latter just the class (this
      is also the syntax to use for assigning aliases). In Visual Studio, you
      can right-click any unresolved class name and choose "Resolve" to
      automatically add the appropriate import.
      >
      --
      J.

      Comment

      • tshad

        #4
        Re: namespace not found


        "tshad" <tshad@dslextre me.comwrote in message
        news:OpO$ryc5IH A.4908@TK2MSFTN GP04.phx.gbl...
        Great thanks,
        >
        Also as an aside,

        I assume I would need both namespaces:

        using System.Collecti ons.Specialized ;
        using System.Collecti ons

        or in my case - 3 of them:

        using System.Collecti ons.Specialized ;
        using System.Collecti ons;
        using System.Collecti ons.Generic;

        using System.Collecti ons won't do it for all of them. Only classes within
        System.Collecti ons.

        Thanks,

        Tom
        Tom
        >
        "Jeroen Mostert" <jmostert@xs4al l.nlwrote in message
        news:4877eda0$0 $14346$e4fe514c @news.xs4all.nl ...
        >tshad wrote:
        >>I am setting a string collection as:
        >>>
        >>Specialized.S tringCollection s1
        >>>
        >>But I get an error saying
        >>>
        >>namespace name 'Specialized' not found.
        >>>
        >>System.Collec tions.Specializ ed.StringCollec tion s1 does work.
        >>>
        >>But I do have:
        >>>
        >>using System.Collecti ons;
        >>>
        >>Why doesn't the program recognize this and force me to put the whole
        >>namespace in?
        >>>
        >Because namespaces do not work that way. Or rather, using directives do
        >not work that way. Namespaces must always be referred to by their full
        >name. This arguably prevents some readability issues, because it saves
        >you from wondering whether "Specialize d" is a namespace or a class in
        >System.Collect ions (with StringCollectio n as a nested class).
        >>
        >If you want a shorthand, then use either
        >>
        > using System.Collecti ons.Specialized ;
        >>
        >or
        >>
        > using StringCollectio n =
        >System.Collect ions.Specialize d.StringCollect ion;
        >>
        >The former imports the whole namespace and the latter just the class
        >(this is also the syntax to use for assigning aliases). In Visual Studio,
        >you can right-click any unresolved class name and choose "Resolve" to
        >automaticall y add the appropriate import.
        >>
        >--
        >J.
        >
        >

        Comment

        Working...