Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编译错误CS1001。将Java转换为C#_C# - Fatal编程技术网

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

编译错误CS1001。将Java转换为C#,c#,C#,CS1001=预期的标识符 我从Java中提取了一段代码,我想用C#测试它。它有一个计算经验的公式,需要在一个我想使用的视频游戏项目中升级。我最近刚刚开始自学代码,所以转换这段代码对我来说是反复试验,但我已经消除了其他13个错误,这一个让我卡住了 缺少一个标识符似乎是一个相当基本的问题,但它也很模糊,我不确定什么时候开始研究。我对错误发生的地方有评论 有什么提示吗 using System; using System.Collections.Generic; using System.Linq;

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);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间控制台应用程序1
{
班级计划
{
浮点数=0;
double output=0;//输出,XP级别总计
float minLevel=2;//要显示的第一个级别
int maxLevel=100;//要显示的最后一个级别
int lvl=0;
void Main()
{
对于(lvl=1;lvl=minLevel)
Console.WriteLine(“级别”+(lvl)+”-“+输出+”EXP”);
输出=数学楼层(点数/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>

这似乎不是唯一的问题…:)

请参阅内联注释:

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);
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间控制台应用程序1
{
班级计划
{
浮点数=0;
双输出=0;
浮动最小水平=2;
int maxLevel=100;
int lvl=0;

void Main()//points+=Math.Floor(lvl+300*Math.Pow(2,lvl/7.0));
7。)
?这不应该是
7.0)
?Java!==JavaScript…模板使用
静态void Main()
在定义变量时,我学会了也必须将它们定义为
静态
,因此我测试了从这两个部分中删除静态,当我没有看到错误时,我感到惊讶。我忘记了替换它们。一些生成错误只有在实际按下
生成
时才会显示在VS中