Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.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
C# 我在C中的数组和整数出现了问题#_C#_Arrays - Fatal编程技术网

C# 我在C中的数组和整数出现了问题#

C# 我在C中的数组和整数出现了问题#,c#,arrays,C#,Arrays,我真的很抱歉,因为我没有用英语写代码,因为我没有写所有的代码,所以你可以理解它 因此,我编辑并删除了我写的帖子,下面是所有代码和一些注释,以帮助您理解它。这个问题标有***,如果我知道这可能是一个非常愚蠢的问题,但我找不到答案 这里是:`//创建自动生成值为100的数组 int arrayNumber=0; 列表数组=新列表() while(true){ 如果(array.Count==100){ 打破 }否则{ array.Add(arrayNumber); arrayNumber++; }

我真的很抱歉,因为我没有用英语写代码,因为我没有写所有的代码,所以你可以理解它

因此,我编辑并删除了我写的帖子,下面是所有代码和一些注释,以帮助您理解它。这个问题标有***,如果我知道这可能是一个非常愚蠢的问题,但我找不到答案

这里是:`//创建自动生成值为100的数组 int arrayNumber=0; 列表数组=新列表()

while(true){
如果(array.Count==100){
打破
}否则{
array.Add(arrayNumber);
arrayNumber++;
} 
}
//更改程序的标题
Console.Title=“在校时间计算器。”;
//打印欢迎信息
Console.WriteLine(“Hi user.!”);
//睡一会儿
睡眠(1500);
//写入下一条消息
Console.WriteLine(“\n请转到学校时间计算器”);
睡眠(2500);
波达增益:
Console.Clear();
//在小时内询问用户何时开始上课
Console.Write(“以小时为单位写出开学时间:”);
睡眠(500);
//创建INT的新变量类型并检查它是否有效
字符串TIMEschoolStarts=Convert.ToString(Console.ReadLine());
int timeSchoolStarts;
if(转换为32(时间选择器开始)<6)
{
timeSchoolStarts=Convert.ToInt32(timeSchoolStarts);
做
{
timeSchoolStarts++;
}而(timeSchoolStarts<6);
}
else if(将.ToInt32(时间选择器开始)>18)
{
timeSchoolStarts=Convert.ToInt32(timeSchoolStarts);
做
{
时间选择部分--;
}while(timeSchoolStarts>18);
}
else if(array.Contains(Convert.ToInt32(TIMEschoolStarts))==false)
{
后藤多益;
}
//为学校开始时的时间(以分钟为单位)创建新变量
Console.Write(“以分钟为单位写出开学时间:”);
睡眠(500);
字符串TimesInMinutes=Convert.ToString(Console.ReadLine());
分钟内;
//检查是否写入了变量并对其进行编辑
如果(TimesInMinutes==“”)
{
最小时间=0;
}
否则{
MinuteTime=转换为32(TimesInMinutes);
}
Console.Clear();
写(“写下你有多少类:”);
int numberOfClasses=Convert.ToInt32(Console.ReadLine());
Console.Clear();
int timeSpentHours,timeSpentMinutes,timeSpent;
//给出了在学校花费的时间的新价值
timespunt=numberOfClasses*45+(numberOfClasses-2)*5+20;
TimePentHours=TimePent/60;
timeSpentMinutes=timeSpent%60;
//为变量提供新的时间值
// ****            
timeSchoolStarts+=TimeSpuntHours;
// ****
MinuteTime+=时间间隔分钟;
//在学校结束时向用户打印值
WriteLine(“学校在{0}小时,{1}分钟内结束。\n在学校花费的总时间是{2}小时,{3}分钟。”,timeSchoolStarts,MinuteTime,TimePentHours,TimePentMinutes);
睡眠(4000);
编写(“\Type RUN to start program:”);
string再次=Convert.ToString(Console.ReadLine());
如果(同样是.ToUpper()=“运行”){
后藤多益`
附言:我只是想知道这是一个计算在校时间的程序。如果你找到更好的方法来创建它,请发布


来自塞尔维亚的问候!

首先:ReadLine()的返回值是字符串,不需要转换

第二:do while循环也是不必要的

第三:goto是一个干净代码中的禁忌


第四:是“niz”数组和您的目标是什么?

请提供实际的错误消息,并指出导致错误的代码行。您发布的代码中没有数组…不确定代码是否与帖子相关-请检查。您的代码中有一些奇怪的解决方案,但在我们解决这些问题之前,您需要详细说明问题所在是。
vremeCas+=trajanjeCas
在代码中不存在。另外,如果你能将变量名翻译成英语,这将非常有帮助,因为我们大多数人都不知道
trajanjeCas
的意思。我在任何地方都看不到数组,哈哈。我确实看到了大量在转换时没有异常处理的尝试,也许这个问题是经过措辞的错了吗?
        while(true){
            if (array.Count == 100){

                break;
            } else{
            array.Add(arrayNumber);
                arrayNumber++;

            } 
        }



        // Changes the title of program
        Console.Title = "Calculator of time spent in school.";

        // Prints welcome message
        Console.WriteLine("Hi user.!");

        // Sleeps for a while
        Thread.Sleep(1500);

        // Writes the next message
        Console.WriteLine("\nWelcome to Calculator of time spent in school.");

        Thread.Sleep(2500);

    DoAgain:

        Console.Clear();

        // Asks user when school starts in hours
        Console.Write("Write the time when school starts in hours: ");

        Thread.Sleep(500);

        // Creates new variable type of INT and checks is it valid
        string TIMEschoolStarts = Convert.ToString(Console.ReadLine());
        int timeSchoolStarts;

        if (Convert.ToInt32(TIMEschoolStarts) < 6)
        {
            timeSchoolStarts = Convert.ToInt32(TIMEschoolStarts);
            do
            {
                timeSchoolStarts++;

            } while (timeSchoolStarts < 6);

        }
        else if (Convert.ToInt32(TIMEschoolStarts) > 18)
        {
            timeSchoolStarts = Convert.ToInt32(TIMEschoolStarts);
            do
            {
                timeSchoolStarts--;

            } while (timeSchoolStarts > 18);

        }
        else if (array.Contains(Convert.ToInt32(TIMEschoolStarts)) == false)
        {
            goto DoAgain;
        }

        // Creates new variable for the Time in Minutes when school starts
        Console.Write("Write the time when school starts in minutes: ");
        Thread.Sleep(500);
        string TimesInMinutes = Convert.ToString(Console.ReadLine());
        int minutesTime;

        // Checks is variable written and edit it
        if (TimesInMinutes == "")
        {
            minutesTime = 0;

        }
        else {
            minutesTime = Convert.ToInt32(TimesInMinutes);
        }

        Console.Clear();

        Console.Write("Write how much classes you have: ");
        int numberOfClasses = Convert.ToInt32(Console.ReadLine());

        Console.Clear();

        int timeSpentHours, timeSpentMinutes, timeSpent;

        // Gives new values of time SPENT in school
        timeSpent = numberOfClasses * 45 + (numberOfClasses - 2) * 5 + 20;
        timeSpentHours = timeSpent / 60;
        timeSpentMinutes=timeSpent % 60;

        // Gives new values of time to the variables
        // ****            
        timeSchoolStarts += timeSpentHours;
        // ****
        minutesTime += timeSpentMinutes;

        // Prints the value when school is ending to the user
        Console.WriteLine("School is ending in {0} hours, {1} minutes.\nTotal time spent in school is {2} hours, {3} minutes.", timeSchoolStarts, minutesTime, timeSpentHours, timeSpentMinutes);

        Thread.Sleep(4000);

        Console.Write("\Type RUN to start program again: ");
        string again = Convert.ToString(Console.ReadLine());

        if (again.ToUpper()=="RUN") {
            goto DoAgain;`