编译错误CS1001。将Java转换为C#

时间:2016-09-09 20:47:25

标签: c#

CS1001 =预期标识符

我从Java中获取了一段我希望在C#中测试的代码。它有一个公式来计算我想要使用的视频游戏项目升级所需的经验。我刚刚开始自学代码,所以转换这个对我来说是试错,但是我已经消除了其他13个错误,这个让我陷入困境。

缺少一个标识符似乎是一个非常基本的问题,但它也很模糊,我不确定何时开始研究。我发表了错误发生的地方。

任何提示?

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

namespace ConsoleApplication1
{
class Program
{
    float points = 0; 
    double output = 0; // Output, XP total at level
    float minLevel = 2; // First level to Display
    int maxLevel = 100; // Last Level to Display
    int lvl = 0;

    void Main()
    {

        for (lvl = 1; lvl <= maxLevel; lvl++)
        {
            points += Math.Floor(lvl + 300 * Math.Pow(2, lvl / 7.)); // Compile Error CS1001 at "));"
            if (lvl >= minLevel)
                Console.WriteLine("Level " + (lvl) + " - " + output + " EXP");
            output = Math.Floor(points / 4);
        }
    }
}

}

原始JavaScript代码:

<SCRIPT LANGUAGE="JavaScript">
<!--
document.close();
document.open();
document.writeln('Begin JavaScript output:');
document.writeln('<PRE>');

points = 0;
output = 0;
minlevel = 2; // first level to display
maxlevel = 200; // last level to display

for (lvl = 1; lvl <= maxlevel; lvl++)
{
  points += Math.floor(lvl + 300 * Math.pow(2, lvl / 7.));
  if (lvl >= minlevel)
    document.writeln('Level ' + (lvl) + ' - ' + output + ' xp');
  output = Math.floor(points / 4);
}

document.writeln('</PRE>');
document.close();
// -->
</SCRIPT>

1 个答案:

答案 0 :(得分:1)

这看起来不是唯一的问题......:)

见内联评论:

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

namespace ConsoleApplication1
{
    class Program
    {
        float points = 0; 
        double output = 0;
        float minLevel = 2;
        int maxLevel = 100;
        int lvl = 0;

        void Main() //<-- Bad entry point public static void Main()
        {

            for (lvl = 1; lvl <= maxLevel; lvl++)
            {
                points += (float)Math.Floor(lvl + 300 * Math.Pow(2, lvl / 7.)); // <-- You have to explicitly specify the mantissa if you have a '.' is should be 7.0 or 7f
                            //^--- You also need to cast to a float here because the expression evaluates to a double
                if (lvl >= minLevel)
                    Console.WriteLine("Level " + (lvl) + " - " + output + " EXP");
                output = Math.Floor(points / 4);
            }
        }
    }
}