Simple question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pawelr74@gmail.com

    Simple question

    Hello all,
    I'm beginner in c#. In my web application I have class myTool with few
    public methods. How can I attached this class to other classes and use
    method from myTool class.
    In VB I can use Import, but if I try use using in C# I have
    Error Message
    The type or namespace name 'type/namespace' could not be found (are
    you missing a using directive or an assembly reference?)

    code:
    myTool class is in folder App_Code

    public class myTool
    {

    public int GetIdUser(strin g UserName)
    {
    ............
    }
    public void NewUser(string UserName, string Imie, string Nazwisko)
    {
    .....
    }
    }

    I try use method in class on root application:


    using .....
    using myTool ; /// error message
    public partial class _Default : System.Web.UI.P age
    {

    protected void Page_Load(objec t sender, EventArgs e)
    {

    }
    protected void Login1_LoggedIn (object sender, EventArgs e)
    {
    Session["idUser"] = GetIdUser(Login 1.UserName);
    }
    }

    How can I correct my code?

    Thanks for yours help

    BR.

    Pawel
  • Peter Duniho

    #2
    Re: Simple question

    On Thu, 25 Sep 2008 16:24:34 -0700, <pawelr74@gmail .comwrote:
    Hello all,
    I'm beginner in c#. In my web application I have class myTool with few
    public methods. How can I attached this class to other classes and use
    method from myTool class.
    In VB I can use Import, but if I try use using in C# I have
    Error Message
    The type or namespace name 'type/namespace' could not be found (are
    you missing a using directive or an assembly reference?) [...]
    You may need to add the assembly where the class is defined as a reference
    to your project. Hard to say without literally looking over your
    shoulder, but that's what the error means when it suggests you might be
    missing "an assembly reference".

    You might want to start with some of the tutorial/sample applications on
    the MSDN web site or elsewhere, at least some of which should lead you
    through these sorts of basic mechanics that might be unfamiliar to
    beginners but are essential for getting the compilation environment
    configured correctly. Once you're more familiar with how the IDE works,
    these kinds of error messages will be much less opaque.

    Pete

    Comment

    • Family Tree Mike

      #3
      Re: Simple question

      In VB you didn't use import to help what you have here. You never created
      an
      instance of the myTool class in your code. Something like the following
      would
      be necessary:

      myTool t = new myTool();
      Session["idUser"] = t.GetIdUser(Log in1.UserName);

      There is probably more to it than this though as the instance of myTool may
      need to be kept around. We don't know enough about the myTool class to
      know for sure.

      <pawelr74@gmail .comwrote in message
      news:ae5b8b9f-aa9d-4215-ba18-ec689b17915a@o4 0g2000prn.googl egroups.com...
      Hello all,
      I'm beginner in c#. In my web application I have class myTool with few
      public methods. How can I attached this class to other classes and use
      method from myTool class.
      In VB I can use Import, but if I try use using in C# I have
      Error Message
      The type or namespace name 'type/namespace' could not be found (are
      you missing a using directive or an assembly reference?)
      >
      code:
      myTool class is in folder App_Code
      >
      public class myTool
      {
      >
      public int GetIdUser(strin g UserName)
      {
      ............
      }
      public void NewUser(string UserName, string Imie, string Nazwisko)
      {
      .....
      }
      }
      >
      I try use method in class on root application:
      >
      >
      using .....
      using myTool ; /// error message
      public partial class _Default : System.Web.UI.P age
      {
      >
      protected void Page_Load(objec t sender, EventArgs e)
      {
      >
      }
      protected void Login1_LoggedIn (object sender, EventArgs e)
      {
      Session["idUser"] = GetIdUser(Login 1.UserName);
      }
      }
      >
      How can I correct my code?
      >
      Thanks for yours help
      >
      BR.
      >
      Pawel

      Comment

      • Hans Kesting

        #4
        Re: Simple question

        pawelr74@gmail. com expressed precisely :
        Hello all,
        I'm beginner in c#. In my web application I have class myTool with few
        public methods. How can I attached this class to other classes and use
        method from myTool class.
        In VB I can use Import, but if I try use using in C# I have
        Error Message
        The type or namespace name 'type/namespace' could not be found (are
        you missing a using directive or an assembly reference?)
        >
        code:
        myTool class is in folder App_Code
        >
        public class myTool
        {
        >
        public int GetIdUser(strin g UserName)
        {
        ............
        }
        public void NewUser(string UserName, string Imie, string Nazwisko)
        {
        .....
        }
        }
        >
        I try use method in class on root application:
        >
        >
        using .....
        using myTool ; /// error message
        public partial class _Default : System.Web.UI.P age
        {
        >
        protected void Page_Load(objec t sender, EventArgs e)
        {
        >
        }
        protected void Login1_LoggedIn (object sender, EventArgs e)
        {
        Session["idUser"] = GetIdUser(Login 1.UserName);
        }
        }
        >
        How can I correct my code?
        >
        Thanks for yours help
        >
        BR.
        >
        Pawel
        Does that class (myTool) live in a namespace? If not, add something
        like this around your class:

        namespace MyToolsNamespac e
        {
        // your class definition
        }


        The "using directive" accepts only namespaces, not classnames.
        So that would be "using MyToolsNamespac e;", using the example above.

        And as Mike said, you need an instance of this class to use it's
        methods.

        By the way, the regular naming conventions specify that a classname
        should start with an uppercase letter (MyTool).

        Hans Kesting


        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Simple question

          On Sep 26, 12:24 am, pawel...@gmail. com wrote:
          I'm beginner in c#. In my web application I have class myTool with few
          public methods. How can I attached this class to other classes and use
          method from myTool class.
          In VB I can use Import, but if I try use using in C# I have
          Error Message
          The type or namespace name 'type/namespace' could not be found (are
          you missing a using directive or an assembly reference?)
          The using directive is used to make a *namespace* available, not a
          type. What namespace is "myTool" in?

          Jon

          Comment

          • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

            #6
            Re: Simple question

            In a web application the IDE does not add a namespace for these helper
            classes. A namespace is not really necessary in this case. You are correct
            that a using statement would need a namespace though.

            "Hans Kesting" wrote:
            pawelr74@gmail. com expressed precisely :
            Hello all,
            I'm beginner in c#. In my web application I have class myTool with few
            public methods. How can I attached this class to other classes and use
            method from myTool class.
            In VB I can use Import, but if I try use using in C# I have
            Error Message
            The type or namespace name 'type/namespace' could not be found (are
            you missing a using directive or an assembly reference?)

            code:
            myTool class is in folder App_Code

            public class myTool
            {

            public int GetIdUser(strin g UserName)
            {
            ............
            }
            public void NewUser(string UserName, string Imie, string Nazwisko)
            {
            .....
            }
            }

            I try use method in class on root application:


            using .....
            using myTool ; /// error message
            public partial class _Default : System.Web.UI.P age
            {

            protected void Page_Load(objec t sender, EventArgs e)
            {

            }
            protected void Login1_LoggedIn (object sender, EventArgs e)
            {
            Session["idUser"] = GetIdUser(Login 1.UserName);
            }
            }

            How can I correct my code?

            Thanks for yours help

            BR.

            Pawel
            >
            Does that class (myTool) live in a namespace? If not, add something
            like this around your class:
            >
            namespace MyToolsNamespac e
            {
            // your class definition
            }
            >
            >
            The "using directive" accepts only namespaces, not classnames.
            So that would be "using MyToolsNamespac e;", using the example above.
            >
            And as Mike said, you need an instance of this class to use it's
            methods.
            >
            By the way, the regular naming conventions specify that a classname
            should start with an uppercase letter (MyTool).
            >
            Hans Kesting
            >
            >
            >

            Comment

            Working...