标签: console-application

如何让控制台应用程序每月运行一次(而不是更多)一个函数,无限期?

编写一个C#应用程序来运行一些预定的任务,我真正需要的就是持续监控日期和时间,并在每个月的28号召唤一次功能,然后耐心地等待下一个28日一个月到来.

我想它会以某种方式使用System.Threading.Thread.Sleep(),但至于它应该运行的具体条件,以及如何防止它在相关日期多次运行,我不是当然...

任何帮助非常感谢:)

c# .net-4.0 console-application

-2
推荐指数
1
解决办法
1649
查看次数

为什么计算小数(34+)的阶乘返回0

int n = Convert.ToInt32(Console.ReadLine());
int factorial = 1;

for (int i = 1; i <= n; i++)
{
    factorial *= i;    
}
Console.WriteLine(factorial);
Run Code Online (Sandbox Code Playgroud)

此代码在控制台应用程序中运行,但当数字大于34时,应用程序返回0.

为什么返回0以及如何计算大数的阶乘?

c# console-application

-2
推荐指数
1
解决办法
1589
查看次数

如何在Console应用程序中读取XML文件

我将给出一组我在w3schools XML示例中找到的简单xml行.

我想知道如何从控制台应用程序访问这些数据(我通过控制台应用程序项目插入了app.config)

<?xml version="1.0" encoding="ISO-8859-1"?>
 <bookstore>
   <book category="cooking">
     <title lang="en">Everyday Italian</title>
     <author>Giada De Laurentiis</author>
     <year>2005</year>
     <price>30.00</price>
   </book>
   <book category="children">
     <title lang="en">Harry Potter</title>
     <author>J K. Rowling</author>
     <year>2005</year>
     <price>29.99</price>
   </book>
 </bookstore>
Run Code Online (Sandbox Code Playgroud)

c# xml console-application visual-studio

-2
推荐指数
1
解决办法
1万
查看次数

C#无法识别两个变量

我正在尝试用C#编写一个简单的计算器.但由于某种原因,程序无法识别2个变量.这是代码的第52行:

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

namespace Calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your first number: ");
            string num1 = Console.ReadLine();
            //Convert the string to a integer and check if it contains a number
            try
            {
                int number1 = Convert.ToInt32(num1);
            }
            catch (FormatException e)
            {
                Console.WriteLine("That was not a number!");
            }
            catch (OverflowException e)
            {
                Console.WriteLine("Wow, not so many numbers..");
            }

            Console.WriteLine("Press / * + or -: ");
            string symbol …
Run Code Online (Sandbox Code Playgroud)

c# console-application

-2
推荐指数
1
解决办法
154
查看次数

对if语句施加限制

这是一个非常基本的问题,但我如何只在if语句中允许数字值?例如,如果用户输入字符串作为id,则应该给出错误,说明只允许数值.

Console.Write("Please enter your ID: ");
int id = Int32.Parse(Console.ReadLine());
if () // what should I write here?
{
    Console.WriteLine("Only Numeric value are allowed.");
}else{
Console.WriteLine("My ID is {0}", id);}
Run Code Online (Sandbox Code Playgroud)

c# if-statement console-application

-2
推荐指数
1
解决办法
174
查看次数

换行符'/ n'将被打印而不是拆分为换行符

为了澄清,我理解我可以使用:

Console.WriteLine("sample text")
Run Code Online (Sandbox Code Playgroud)

为了获得理想的效果,尽管如此,我正在使用的代码应该可以工作,我想知道为什么它不是.

代码示例:

Console.Write("You have chosen {0}, the game will now begin.{1} Newline.", x_or_o, "/n");
Run Code Online (Sandbox Code Playgroud)

我在控制台中收到的输出是:

You have chosen x, the game will now begin./n Newline.
Run Code Online (Sandbox Code Playgroud)

而我想要的输出是:

You have chosen x, the game will now begin.
Newline.
Run Code Online (Sandbox Code Playgroud)

对不起,如果我遗漏了一些基本或明显的东西,但我的搜索引擎优化和谷歌搜索都没有解决方案.

所有答案都提前感谢,谢谢您的时间.

c# console-application

-2
推荐指数
1
解决办法
52
查看次数

堆栈溢出异常,没有递归

我遇到堆栈溢出异常的问题,但我不知道是什么导致异常被抛出.我正在使用一个类库,其中包含我需要的所有方法和对象,并从控制台应用程序运行它.

任何帮助将不胜感激,因为这是一个任务的一部分,将在几个小时内到期.

这是我的代码:

TrafficIncidentNotificationRadiusCalculator类

namespace TrafficIncident
{
public class TrafficIncidentNotificationRadiusCalculator
{
    public double meters;
    public double CONFIGURED_NOTIFICATION_RADIUS
    {
        get { return CONFIGURED_NOTIFICATION_RADIUS; }
        set { CONFIGURED_NOTIFICATION_RADIUS = meters; }
    }

    public List<string> GetNotificationRecipientsList(List<User> users, List<UserLocationUpdate> userLocation, TrafficIncidentReport report)
    {
        int i = 0;
        List<string> userNotificationIds = new List<string>();
        while (i < userLocation.Count)
        {
            UserLocationUpdate userLoc = userLocation.ElementAt(i);
            userNotificationIds.Add(userLoc.userNotificationId);
            Console.WriteLine(userNotificationIds.ElementAt(i));
            i++;
        } 
        return userNotificationIds;
    }
}
}
Run Code Online (Sandbox Code Playgroud)

TrafficIncidentReport类

namespace TrafficIncident
{
public class TrafficIncidentReport
{
    public double[] incidentLocation;

    public double latitude …
Run Code Online (Sandbox Code Playgroud)

c# stack-overflow class-library console-application

-2
推荐指数
1
解决办法
121
查看次数

无法将文本写入文件

所以,基本上,我试图在我的文本 rpg 中创建一个保存点。我想通过使用 .txt 文件并以这种方式跳转到每个方法来做到这一点。但是,当我尝试输入文件的路径和字符串内容时,它返回 CS0029 错误并指出它无法将 void 转换为字符串。

public void PickingUpScroll()
    {

        savePoint = "PickingUpScroll";
        saveData = File.WriteAllText(savePath, savePoint);
         
        hasFireMagic = true;

        Console.WriteLine("You approach the strange scroll in your room and pick it up. A strange light eminates from the foreign symbols on the paper. You feel a warmth in your hands.\nLooking down, you notice they are glowing with a strange light, almost like fire.");
        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.WriteLine("You have accquired 'Fire Magic'");
        Console.ForegroundColor = ConsoleColor.White;


        if (hasWeapons == …
Run Code Online (Sandbox Code Playgroud)

c# console-application

-2
推荐指数
1
解决办法
81
查看次数

如何从另一个班级调用Main?

因此,我正在编写一个简单的计算器C#控制台程序,我只是在学习C#。

这是我要称为main的地方:

if (info.Key == ConsoleKey.Escape)
{
    Environment.Exit(0);
}
else
{
}
Run Code Online (Sandbox Code Playgroud)

我想称呼main为加法,减法,乘法和除法类,因此它可以回到开始时询问“按'A'进行加法”等操作的地方。

我尝试放入“ Main();” 在其他情况下,但它给了我一个错误,并说“没有给定的参数对应于'Program.Main(String [])的所需形式参数'args'”

我该如何在此类中调用main,以便转到main的开头?

c# console program-entry-point calculator console-application

-3
推荐指数
1
解决办法
5008
查看次数

如何在表格中显示数字(0 1 1 2 3 5 8 13)

如何在表格中显示数字(0 1 1 2 3 5 8 13)这样显示数字前1个数字然后第二个是加上先前的数字=> 0然后是1然后1 + 0 = 1然后1 + 1 = 2然后1 + 2 = 3等等?

using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {

            for (int i = 0; i < 20; i++)
            {
                Console.Write(i) ;
            }
            Console.ReadKey();             
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

请提供一些代码

c# console-application

-3
推荐指数
1
解决办法
541
查看次数