small problem

F

fataneh

hi every body;
i wrote a program that it has error ;plz help me :(
using System;
namespace ConsoleApplication45
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("***********");
for (int i = 0; i < 1008; i++)
{
Console.BackgroundColor = ConsoleColor.DarkCyan;
Console.Write(" ");
}
move(); // ***********error is for
here***********************************************
}
class fat
{
void move()
{
int i;
for(i=0;i<10;i++)
{
Console.WriteLine(i);
}
}
}
}
}
 
F

Family Tree Mike

hi every body;
i wrote a program that it has error ;plz help me :(
using System;
namespace ConsoleApplication45
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("***********");
for (int i = 0; i< 1008; i++)
{
Console.BackgroundColor = ConsoleColor.DarkCyan;
Console.Write(" ");
}
move(); // ***********error is for
here***********************************************
}
class fat
{
void move()
{
int i;
for(i=0;i<10;i++)
{
Console.WriteLine(i);
}
}
}
}
}

Either:
1. change the call where the error is to "fat.move();", after marking
the method as "static".
2. create an instance of fat before calling the method, as:
fat f = new fat();
f.move();

From the code posted, I would use option 1.
 
F

fataneh

hi every body;
i wrote a program that it has error ;plz help me  :(
using System;
namespace ConsoleApplication45
{
     class Program
     {
         static void Main(string[] args)
         {
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine("***********");
             for (int i = 0; i<  1008; i++)
             {
                 Console.BackgroundColor = ConsoleColor.DarkCyan;
                 Console.Write(" ");
             }
            move(); // ***********error is for
here***********************************************
         }
         class fat
         {
             void move()
             {
                 int i;
                 for(i=0;i<10;i++)
                 {
                     Console.WriteLine(i);
                 }
             }
         }
     }
}

Either:
1. change the call where the error is to "fat.move();", after marking
the method as "static".
2. create an instance of fat before calling the method, as:
   fat f = new fat();
   f.move();

 From the code posted, I would use option 1.

thanks a lot mike; but it has error too;
 
K

Konrad Neitzel

Hi Fataneh!

thanks a lot mike; but it has error too;

Please. Give the error you get. That will help us a lot ot help you. We
normaly do not want to create such a project on our own, too (Because it
simply take much longer than it has to take!)

The error message is quite clear - so maybe you should try to check out
the MSDN Library. Normaly you get nice explanations there that helps you
to understand what the problem is.

Now completly to the remaining problem:

The Function move() is private and cannot be called from outside. Make
it public and it can be called.

The code could look like:

using System;
namespace ConsoleApplication45
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("***********");
for (int i = 0; i< 1008; i++)
{
Console.BackgroundColor = ConsoleColor.DarkCyan;
Console.Write(" ");
}
Fat.Move();
}

class Fat
{
public static void Move()
{
int i;
for (i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
}
}
}
}

(I also did a little refactoring - Classes and Function names should be
PascalCase and not camelCase - so I switched to uppercase letter. And
even when you write some simple code, you should choose some reasonable
names. Else you get problems when you read the code later. But of
course: That has nothing to do with the main problem.)

With kind regards,

Konrad
 
F

fataneh

Hi Fataneh!


thanks a lot mike; but it has error too;

Please. Give the error you get. That will help us a lot ot help you. We
normaly do not want to create such a project on our own, too (Because it
simply take much longer than it has to take!)

The error message is quite clear - so maybe you should try to check out
the MSDN Library. Normaly you get nice explanations there that helps you
to understand what the problem is.

Now completly to the remaining problem:

The Function move() is private and cannot be called from outside. Make
it public and it can be called.

The code could look like:

using System;
namespace ConsoleApplication45
{
     class Program
     {
          static void Main(string[] args)
          {
              Console.ForegroundColor = ConsoleColor.Red;
              Console.WriteLine("***********");
              for (int i = 0; i<  1008; i++)
             {
                  Console.BackgroundColor = ConsoleColor.DarkCyan;
                 Console.Write(" ");
             }
             Fat.Move();
          }

          class Fat
          {
              public static void Move()
              {
                  int i;
                  for (i = 0; i < 10; i++)
                  {
                      Console.WriteLine(i);
                  }
              }
          }
      }
 }

(I also did a little refactoring - Classes and Function names should be
PascalCase and not camelCase - so I switched to uppercase letter. And
even when you write some simple code, you should choose some reasonable
names. Else you get problems when you read the code later. But of
course: That has nothing to do with the main problem.)

With kind regards,

Konrad
hi dear konrad;
thanks alot :)
it works without any error & i undrestand what is the problem
 
K

Konrad Neitzel

Hi Fataneh!

hi dear konrad;
thanks alot :)
it works without any error & i undrestand what is the problem

I am glad that I could help you.

With kind regards,

Konrad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top