By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,883 Members | 1,952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,883 IT Pros & Developers. It's quick & easy.

Help please... instance reference; qualify it with a type name instead

P: 19
Hi:
I have 3 class/Methods:
the first one:just beeps
the second one:ask the user to Enter the number of beep
The last one:Activate and runs.
I get the following Error:"instance reference; qualify it with a type name instead "
Can you please re-write the code and fix it for me,Thanks.

First One:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. public class AmbulanceSiren
  3. {
  4.  
  5.     public void Siren(int pattern)
  6.     {
  7.         for (int i=0;i< pattern; i++)
  8.         {
  9.             Console.Beep();
  10.             Console.Write("");
  11.         }
  12.         }
  13. }
  14.  
Second One:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. public class User
  3. {
  4.  
  5.     public static void Enter()
  6.     {
  7.         Console.WriteLine("Enter The Pattern:");
  8.         AmbulanceSiren Test = new AmbulanceSiren();
  9.         int repeat = Convert.ToInt32(Console.ReadLine());
  10.         Test.Siren(repeat);
  11.  
  12.     }
  13. }
  14.  
Last One:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. public class Driver
  3. {
  4.  
  5.     public static void Main(string[] args)
  6.     {
  7.         User Active = new User();
  8.  
  9.         Active.Enter();
  10.     }
  11. }
  12.  
Feb 18 '09 #1
Share this Question
Share on Google+
2 Replies


tlhintoq
Expert 2.5K+
P: 3,525
Can you please re-write the code and fix it for me,Thanks.
Asking someone else to do your homework (or thinking) (or debugging) for you doesn't teach you anything.

You didn't even mention where the error occurred. Visual Studio should have given you a line number for it.
Feb 19 '09 #2

vekipeki
Expert 100+
P: 229
Well, it looks like Active.Enter(); will throw that error, because Enter() is a static method, while Active is an instance of User class. There is also no reason why you couldn't make AmbulanceSiren.Siren() static.

You should consider giving your classes names that are meaningful, because Active.Enter(); doesn't really tell you anything about what that method does, or what functionality is enclosed in that class.
Feb 20 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.