【问题标题】:Namespace Error on MonoDevelopMonoDevelop 上的命名空间错误
【发布时间】:2012-04-23 21:34:24
【问题描述】:

我收到以下错误。 1:命名空间“System”中不存在类型或命名空间名称“CountDownTime”(您是否缺少程序集引用) 2:命名空间 Andriod.OS 中不存在类型或命名空间 naem 'Runtime'(您是否缺少程序集引用)

我希望代码生成 10 个减法问题,给出答案,然后给出测试所花费的时间。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CountDownTimer;

using Android.App;
using Android.Content;
using Android.OS.Runtime;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android;

namespace Jagtutor
{
    public class Subtraction : View
    {
        public Subtraction (Context context, IAttributeSet attrs) :
            base (context, attrs)
        {
            Initialize ();
        }

        public Subtraction (Context context, IAttributeSet attrs, int defStyle) :
            base (context, attrs, defStyle)
        {
            Initialize ();
        }

        private void Initialize ()
        {
            int correctCount;
            int count = 0;
            long startTime = CountDownTimer(0);

            while (count < 10)
            {
                // Generate two random single-digit numbers
                srand(CountDownTimer(0));
                int number1 = Random() % 10;
                int number2 = Random() % 10;

                // if number1 < number, swap number1 with number2
                if (number1 < number2)
                {
                    int temp = number1;
                    number1 = number2;
                    number2 = temp; 

                    // PROMPT THE STUDENT TO ANSWER " WHAT IS NUMBERE1 - NUMBER2?"
                    Console.WriteLine("WHAT IS ")(number1);" - "(number2)("?");

                    // Grade the answer and display the result
                    if (number1 - number2 == answer){
                        Console.Write("You are correct!");
                        correctCount++;
                    }
                    else
                        Console.WriteLine("Your answer is wrong");
                    Console.WriteLine(number1);"-"(number2); " should be" (number1 - number2);

                    // increase the count 
                    count++;
                }
                long endTime = CountDownTimer(0);
                long testTime = endTime - startTime; 

                Console.Write(" Correct count is ")(correctCount);" Test time is" (testTime)("seconds");
                return 0;
            }

        }
    }

}

【问题讨论】:

  • 请在 Stack Overflow 上学习如何格式化您的代码,以解决您的下一个问题。这里的代码格式化程序不喜欢制表符,所以最好只使用空格。将代码粘贴到编辑框中后,选择整个代码并按Ctrl+K 或单击编辑框上方的{} 图标。

标签: c# namespaces compiler-errors monodevelop xamarin.android


【解决方案1】:

C# using directive 用于命名空间,而不是类型。没有System.CountDownTimer 命名空间,因此出现错误。

就此而言,也没有System.CountDownTimer 类型;这是Android.OS.CountDownTimer,所以你需要:

using Android.OS;

同样,没有Android.OS.Runtime命名空间,所以using Android.OS.Runtime;也会产生编译时错误;删除它。

【讨论】:

    【解决方案2】:

    与其他的,添加:

    using Android.OS;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-23
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      • 2014-08-01
      相关资源
      最近更新 更多