skip to Main Content
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace MyFirstProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            
        


        }
    }
}

And another class in another file

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

namespace Rock_Paper_Scissors
{
    internal class ComputerGenerateSign
    {
       public string computer;

        Console.ReadKey()


    }
}

Why Visual Studio code have a problem ?>"Error IDE1007 The name ‘Console.ReadKey’ does not exist in the current context"

2

Answers


  1. Use ‘Console.ReadKey();’ in the body of a method, That way it will recognize. You didn’t write a method inside the ‘ComputerGenerateSign’ class like the class ‘program’ has the main method. hope this helps.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Rock_Paper_Scissors
    {
        public class ComputerGenerateSign
        {
            public void method1()
            {
                public string computer;
    
                Console.ReadKey();
            }
           
        }
    }
    
    Login or Signup to reply.
  2. You have made function call in class which was not allowed. In class you can define properties, fields and functions.

    You need to call that function inside a function body.

    Main.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Rock_Paper_Scissors;
    
    
    namespace MyFirstProgram
    {
        class Program
        {
            static void Main(string[] args)
            {
                ComputerGenerateSign obj=new ComputerGenerateSign(); 
                obj.WaitForUserInput(); 
            }
        }
    }
    

    And another class in another file

    using System;
    using System.Text;
    
    namespace Rock_Paper_Scissors
    {
        public class ComputerGenerateSign
        {
            public string computer;
    
            public void WaitForUserInput()
            {           
                Console.ReadKey();
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search