-1

I'm trying to write a program that writes text char by char. And I want to choose a write speed using enum. But it throws an error. So, this is my code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace WritingApp
{
    class Program
    {
        public enum WriteMode { Slow, SlowRandom, Normal, NormalRandom, Fast, FastRandom };

        static void Main(string[] args)
        {
            MessageWrite("smth", WriteMode.Fast); //Error here
//An object reference is required for the non-static field, method, or property   
//'Program.MessageWrite(string, Program.WriteMode)'
        }

        void MessageWrite(string message, WriteMode mode)
        {
            for(int i = 0; i < message.Length; i++)
            {
                Console.Write(message[i]);
            }
        }
    }
}
BeLuckyDaf
  • 11
  • 4

1 Answers1

2

You should make MessageWrite static.

static void MessageWrite(string message, WriteMode mode)
{
    for (int i = 0; i < message.Length; i++)
    {
        Console.Write(message[i]);
    }
}

Take a look at Why static methods can't call non-static methods directly?

Community
  • 1
  • 1
Faraz Ahmed
  • 1,467
  • 2
  • 18
  • 33