Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Beginners question

Beginners question

Scheduled Pinned Locked Moved C#
question
8 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    digsy_
    wrote on last edited by
    #1

    I have a method in a separate class file that I'd like to call. The separate file is called dataaccessclass.cs is structured like: using System; namespace aspnetcsharpdemo { /// /// Summary description for Class1. /// public class Class1 { public static string Class11() { // this is the method that would do the select string result = "test"; return result; } } } When I try the following code it fails with - C:\Inetpub\wwwroot\aspnetcsharpdemo\test5.aspx.cs(52): The type or namespace name 'DataAccessSelectClass' could not be found (are you missing a using directive or an assembly reference?) Label1.Text = DataAccessSelectClass.Class11(); Whats the proper way to call the method ?

    S C G S 4 Replies Last reply
    0
    • D digsy_

      I have a method in a separate class file that I'd like to call. The separate file is called dataaccessclass.cs is structured like: using System; namespace aspnetcsharpdemo { /// /// Summary description for Class1. /// public class Class1 { public static string Class11() { // this is the method that would do the select string result = "test"; return result; } } } When I try the following code it fails with - C:\Inetpub\wwwroot\aspnetcsharpdemo\test5.aspx.cs(52): The type or namespace name 'DataAccessSelectClass' could not be found (are you missing a using directive or an assembly reference?) Label1.Text = DataAccessSelectClass.Class11(); Whats the proper way to call the method ?

      S Offline
      S Offline
      Steve
      wrote on last edited by
      #2

      I can't see where your DataAccessSelectClass is coming from? And as it seems, neither can the compiler :-D For the example code you've posted, you should be using

      Text1.Text = Class1.Class11();

      That should give you what you need. Another thing to consider is, if you're going to just return a string that's not going to change, why not set it up as a public const string or as read only property? Steve.

      D 1 Reply Last reply
      0
      • S Steve

        I can't see where your DataAccessSelectClass is coming from? And as it seems, neither can the compiler :-D For the example code you've posted, you should be using

        Text1.Text = Class1.Class11();

        That should give you what you need. Another thing to consider is, if you're going to just return a string that's not going to change, why not set it up as a public const string or as read only property? Steve.

        D Offline
        D Offline
        digsy_
        wrote on last edited by
        #3

        well the code I posted is in a file called DataAccessSelectClass.cs (and its called from a webform1.aspx.cs page) the code inside the method is just temporary - once I figure out how to call it, the code will be changed to return a dataset.

        1 Reply Last reply
        0
        • D digsy_

          I have a method in a separate class file that I'd like to call. The separate file is called dataaccessclass.cs is structured like: using System; namespace aspnetcsharpdemo { /// /// Summary description for Class1. /// public class Class1 { public static string Class11() { // this is the method that would do the select string result = "test"; return result; } } } When I try the following code it fails with - C:\Inetpub\wwwroot\aspnetcsharpdemo\test5.aspx.cs(52): The type or namespace name 'DataAccessSelectClass' could not be found (are you missing a using directive or an assembly reference?) Label1.Text = DataAccessSelectClass.Class11(); Whats the proper way to call the method ?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          digsy_ wrote:

          namespace aspnetcsharpdemo { /// /// Summary description for Class1. /// public class Class1

          What the file is called does not matter. This class is called Class1, or aspnetcsharpdemo.Class1. You're looking for a different class, with a method called Class11 ?? Or is Class11 a class in a namespace called DataAccessSelectClass and your code is totally confused ? Use real class names, not class1 or class11.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          1 Reply Last reply
          0
          • D digsy_

            I have a method in a separate class file that I'd like to call. The separate file is called dataaccessclass.cs is structured like: using System; namespace aspnetcsharpdemo { /// /// Summary description for Class1. /// public class Class1 { public static string Class11() { // this is the method that would do the select string result = "test"; return result; } } } When I try the following code it fails with - C:\Inetpub\wwwroot\aspnetcsharpdemo\test5.aspx.cs(52): The type or namespace name 'DataAccessSelectClass' could not be found (are you missing a using directive or an assembly reference?) Label1.Text = DataAccessSelectClass.Class11(); Whats the proper way to call the method ?

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            As Christina said, the file name is irrelevant. To access the method in the class you use: Label1.Text = aspnetcsharpdemo.Class1.Class11(); If you would have named your class DataAccessSelectClass instead of Class1, you would use: Label1.Text = aspnetcsharpdemo.DataAccessSelectClass.Class11(); And if you had using aspnetcsharpdemo; at the top of your page, or if your page class was inside namespace aspnetcsharpdemo, you could use: Label1.Text = DataAccessSelectClass.Class11();

            --- b { font-weight: normal; }

            1 Reply Last reply
            0
            • D digsy_

              I have a method in a separate class file that I'd like to call. The separate file is called dataaccessclass.cs is structured like: using System; namespace aspnetcsharpdemo { /// /// Summary description for Class1. /// public class Class1 { public static string Class11() { // this is the method that would do the select string result = "test"; return result; } } } When I try the following code it fails with - C:\Inetpub\wwwroot\aspnetcsharpdemo\test5.aspx.cs(52): The type or namespace name 'DataAccessSelectClass' could not be found (are you missing a using directive or an assembly reference?) Label1.Text = DataAccessSelectClass.Class11(); Whats the proper way to call the method ?

              S Offline
              S Offline
              saqib82
              wrote on last edited by
              #6

              use this Label1.Text = aspnetcsharpdemo.Class11();

              sAqIb

              S 2 Replies Last reply
              0
              • S saqib82

                use this Label1.Text = aspnetcsharpdemo.Class11();

                sAqIb

                S Offline
                S Offline
                saqib82
                wrote on last edited by
                #7

                sorry for the mistake use this Label1.Text = aspnetcsharpdemo.Class1.Class11(); means, namespacename.classname.function_name_of_class(); it will work

                sAqIb

                1 Reply Last reply
                0
                • S saqib82

                  use this Label1.Text = aspnetcsharpdemo.Class11();

                  sAqIb

                  S Offline
                  S Offline
                  saqib82
                  wrote on last edited by
                  #8

                  sorry for the mistake use this Label1.Text = aspnetcsharpdemo.Class1.Class11(); means, namespacename.classname.function_name_of_class(); it will work

                  sAqIb

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups