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. Namespace issues

Namespace issues

Scheduled Pinned Locked Moved C#
helpcsharpquestion
9 Posts 5 Posters 0 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.
  • T Offline
    T Offline
    thrakazog
    wrote on last edited by
    #1

    I'm converting a small app from VB.net to C#. While doing so I've noticed something really annoying with the way C# handles namespaces. In VB.net if I have this code: Imports System Public Class Class1 Dim t As Timers.Timer End Class it should be the same as this C# code: using System; public class Class1 { private Timers.Timer t; } However, The C# compiler throws an error on the Timers.Timer. Even though I have "Using System" specified C# doesn't see that Timers.Timer is part of the System namespace. If I write it all out as System.Timers.Timer it compiles but completely defeats the purpose of using a namespace. The code in VB has no problem seeing Timers.Timer as part of the system namespace. Is there a way to fix this issue in C# so that it will understand the namespace? Or, is it just another arguing point for people who want to say VB is better than C#? Thanks,

    M A B 4 Replies Last reply
    0
    • T thrakazog

      I'm converting a small app from VB.net to C#. While doing so I've noticed something really annoying with the way C# handles namespaces. In VB.net if I have this code: Imports System Public Class Class1 Dim t As Timers.Timer End Class it should be the same as this C# code: using System; public class Class1 { private Timers.Timer t; } However, The C# compiler throws an error on the Timers.Timer. Even though I have "Using System" specified C# doesn't see that Timers.Timer is part of the System namespace. If I write it all out as System.Timers.Timer it compiles but completely defeats the purpose of using a namespace. The code in VB has no problem seeing Timers.Timer as part of the system namespace. Is there a way to fix this issue in C# so that it will understand the namespace? Or, is it just another arguing point for people who want to say VB is better than C#? Thanks,

      M Offline
      M Offline
      mcljava
      wrote on last edited by
      #2

      In C# you need to make sure you are referencing the right kind of Timers. System.Windows.Forms.Timers and System.Timers provide functionally different classes of timer logic. In terms of the namespace, make sure you choose the one that suits your application. BTW, if it were not for Microsoft... "Basic" in all of its various forms would have died off years ago. Funny how to keep it alive they made it more like C and then C++ like. And now that there is a CLR differences are petty, so choose the language you want but consider history first before attempting to bash C#. Each language has its own merits. Mike Luster CTI/IVR/Telephony SME

      T 1 Reply Last reply
      0
      • M mcljava

        In C# you need to make sure you are referencing the right kind of Timers. System.Windows.Forms.Timers and System.Timers provide functionally different classes of timer logic. In terms of the namespace, make sure you choose the one that suits your application. BTW, if it were not for Microsoft... "Basic" in all of its various forms would have died off years ago. Funny how to keep it alive they made it more like C and then C++ like. And now that there is a CLR differences are petty, so choose the language you want but consider history first before attempting to bash C#. Each language has its own merits. Mike Luster CTI/IVR/Telephony SME

        T Offline
        T Offline
        thrakazog
        wrote on last edited by
        #3

        I new the exact namespace i was shooting for. I wanted the System.Timers. That's why the System is the only item I'm "Using" in my example code. From my understanding this is the exact reason you put "Using System" in your code so you don't have to write out System. in front of everything. My question is more about the namespace problem than a timer. Also, I'm not trying to bash C# or VB. All those arguments are old and tired. I was just trying to point out that in VB the namespace worked as expected and in C# it did not. I would still like to know how to fix this in C#.

        D 1 Reply Last reply
        0
        • T thrakazog

          I'm converting a small app from VB.net to C#. While doing so I've noticed something really annoying with the way C# handles namespaces. In VB.net if I have this code: Imports System Public Class Class1 Dim t As Timers.Timer End Class it should be the same as this C# code: using System; public class Class1 { private Timers.Timer t; } However, The C# compiler throws an error on the Timers.Timer. Even though I have "Using System" specified C# doesn't see that Timers.Timer is part of the System namespace. If I write it all out as System.Timers.Timer it compiles but completely defeats the purpose of using a namespace. The code in VB has no problem seeing Timers.Timer as part of the system namespace. Is there a way to fix this issue in C# so that it will understand the namespace? Or, is it just another arguing point for people who want to say VB is better than C#? Thanks,

          A Offline
          A Offline
          Ahmad Mahmoud candseeme
          wrote on last edited by
          #4

          Hi Try this

          using System;
          
          namespace MyNamespace
          {
            public class Class1
             {
               private Timers.Timer t;
             }
          }
          

          Ahmad Shaban

          T 1 Reply Last reply
          0
          • T thrakazog

            I'm converting a small app from VB.net to C#. While doing so I've noticed something really annoying with the way C# handles namespaces. In VB.net if I have this code: Imports System Public Class Class1 Dim t As Timers.Timer End Class it should be the same as this C# code: using System; public class Class1 { private Timers.Timer t; } However, The C# compiler throws an error on the Timers.Timer. Even though I have "Using System" specified C# doesn't see that Timers.Timer is part of the System namespace. If I write it all out as System.Timers.Timer it compiles but completely defeats the purpose of using a namespace. The code in VB has no problem seeing Timers.Timer as part of the system namespace. Is there a way to fix this issue in C# so that it will understand the namespace? Or, is it just another arguing point for people who want to say VB is better than C#? Thanks,

            B Offline
            B Offline
            Bob Stanneveld
            wrote on last edited by
            #5

            Hello, This is a problem I faced a few months ago. Not with basic, but I came from a C++ background. Your problem is that the namespace Timers is not available to you! This sounds strange because the namespace resides in the System namespace which you imported. C# does make all classes in the imported namespace available, but not nested namespaces. You can use an alias to solve the problem, or completely import the namespace:

            // Solve problem using aliases
            using Timers = System.Timers;

            // Or use a fully qualified import
            using System.Timers;

            // Or fully qualify the class that you want to use
            public class Class1
            {
            private System.Timers.Timer t;
            }

            Hope this helps. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^] -- modified at 3:32 Tuesday 21st March, 2006

            1 Reply Last reply
            0
            • T thrakazog

              I new the exact namespace i was shooting for. I wanted the System.Timers. That's why the System is the only item I'm "Using" in my example code. From my understanding this is the exact reason you put "Using System" in your code so you don't have to write out System. in front of everything. My question is more about the namespace problem than a timer. Also, I'm not trying to bash C# or VB. All those arguments are old and tired. I was just trying to point out that in VB the namespace worked as expected and in C# it did not. I would still like to know how to fix this in C#.

              D Offline
              D Offline
              darkelv
              wrote on last edited by
              #6

              That Timer belongs to System.Timers namespace, not System. In C# it worked as expectedly, mayb in VB, it guessed which class that you want to use, which it shouldn't, strictly speaking.

              1 Reply Last reply
              0
              • A Ahmad Mahmoud candseeme

                Hi Try this

                using System;
                
                namespace MyNamespace
                {
                  public class Class1
                   {
                     private Timers.Timer t;
                   }
                }
                

                Ahmad Shaban

                T Offline
                T Offline
                thrakazog
                wrote on last edited by
                #7

                This code produces the same issue. Timers is not found.

                1 Reply Last reply
                0
                • T thrakazog

                  I'm converting a small app from VB.net to C#. While doing so I've noticed something really annoying with the way C# handles namespaces. In VB.net if I have this code: Imports System Public Class Class1 Dim t As Timers.Timer End Class it should be the same as this C# code: using System; public class Class1 { private Timers.Timer t; } However, The C# compiler throws an error on the Timers.Timer. Even though I have "Using System" specified C# doesn't see that Timers.Timer is part of the System namespace. If I write it all out as System.Timers.Timer it compiles but completely defeats the purpose of using a namespace. The code in VB has no problem seeing Timers.Timer as part of the system namespace. Is there a way to fix this issue in C# so that it will understand the namespace? Or, is it just another arguing point for people who want to say VB is better than C#? Thanks,

                  A Offline
                  A Offline
                  Ahmad Mahmoud candseeme
                  wrote on last edited by
                  #8

                  Hi I found the following Timer Class is a part of the System.Threading namespace hence the code should be

                  using System;
                  using System.Threading;
                  
                  namespace MyNamespace
                  {  
                  	
                  	public class Class1   
                  	{     
                  		private Timer MyTimer;
                  	}
                  }
                  

                  navigate to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingtimerclasstopic.asp[^] Thanks Ahmad Shaban -- modified at 2:30 Wednesday 22nd March, 2006

                  A 1 Reply Last reply
                  0
                  • A Ahmad Mahmoud candseeme

                    Hi I found the following Timer Class is a part of the System.Threading namespace hence the code should be

                    using System;
                    using System.Threading;
                    
                    namespace MyNamespace
                    {  
                    	
                    	public class Class1   
                    	{     
                    		private Timer MyTimer;
                    	}
                    }
                    

                    navigate to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingtimerclasstopic.asp[^] Thanks Ahmad Shaban -- modified at 2:30 Wednesday 22nd March, 2006

                    A Offline
                    A Offline
                    Ahmad Mahmoud candseeme
                    wrote on last edited by
                    #9

                    Hi sorry i was in a rush i found this Note System.Threading.Timer is a simple, lightweight timer that uses callback methods and is served by threadpool threads. You might also consider System.Windows.Forms.Timer for use with Windows forms, and System.Timers.Timer for server-based timer functionality. These timers use events and have additional features. for more info http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingtimerclasstopic.asp[^] Ahmad Shaban

                    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