Lỗi the name does not exist in the current context năm 2024

I ran my source code for the FitnessFrog app and the compiler said that the name 'Console' doesn't exist in the current context. What does this mean and why does this happen? I'll put the code below if it can be of help.

class Program {

static void Main()
{
  int runningTotal = 0;
  bool keepGoing = true;
  while(keepGoing)
  {
        //Prompt the use for minutes exercised
        Console.Write("Enter how many minutes you exercised or type /"quit/" to exit: ");
        string entry = Console.ReadLine();
    if (entry == "quit")
    {
        keepGoing = false;
    }
    else
    {
        int minutes = int.Parse(entry);
        runningTotal = runningTotal  + minutes;
        //Repeat until the user quits
        Console.WriteLine("You've entered " + runningTotal + " minutes");
     }
      Console.WriteLine("Goodbye");
  }
} }

3 Answers

Lỗi the name does not exist in the current context năm 2024

seal-mask

STAFF

Hi there! I received your request for assistance. Ben Reynolds is correct. You're going to need to change those slashes. But that's not why you're getting your current error.

The reason you're getting your current error is that you've not included the namespace nor told it using System. The Console class belongs to to the System class. Without having imported or using a class where Console is defined, the compiler will have no idea what you mean. Take a look at the code posted in the "Teacher's Notes". Your code should start with using System; and your class should be nested inside the namespace.

using System;

namespace Treehouse.FitnessFrog {

// Your Program class goes here
}

Hope this helps!

Lỗi the name does not exist in the current context năm 2024

PLUS

Two of the curly brackets got out of the code example itself - sorry about that. Please keep this in mind and don't think of it as a programming error! I did add those brackets to the code in my workspace.

Xóa hết cácweb form đi làm lại từ đầu nên đã ok rồi. Nhưng mà vẫn không biết nguyên nhân của lỗi này là gì [IMG]images/smilies/biggrin.png[/IMG]

Bạn không phải xóa những thứ đó, hãy thử làm như sau: Trong Form Login bạn hãy khai báo Username là public, như vậy bạn có thể truy cập trường này bất cứ trên Form nào với cú pháp như bạn đang làm.


  • >
    Lỗi the name does not exist in the current context năm 2024
    Gửi bởi _G7_
    Xóa hết cácweb form đi làm lại từ đầu nên đã ok rồi. Nhưng mà vẫn không biết nguyên nhân của lỗi này là gì [IMG]images/smilies/biggrin.png[/IMG]

Mình cũng bị lỗi tương tự, nhưng là "txtUsername" không nhận trong sự kiện kích vào nút đăng nhập , google thì tìm ra bài này, website mình dùng 8 webform, thêm mấy webform có sẵn của asp.net login,register,about. Mình làm 7 webform thì nhận được hết, nhưng tạo ra webform thứ 8 thì báo lỗi "txtUsernam" does not exist in the current context". Ban đầu mình cũng xóa hết, làm tới webform thứ 8 thì lại bị như cũ, cuối cùng mình xóa mấy webform có sẵn đi, thì được, mình không hiểu nguyên nhân là gì? Hay là do nhiều webform quá nên nó không nhận. Có ai biết nguyên nhân lỗi này không? [IMG]images/smilies/icon_question.gif[/IMG]

-
  • > Bác bấm chuột phải vào Websolution chọn convert to webapplication . Đa số bị lỗi này do ko khai báo đối tượng label mới -