for循环的问题,并尝试从列表字符串到日期时间的转换中拆分列表声明

问题描述

因此,我正在尝试制作一个“ PTO计算器”,该计算器将计算工作日中剩余年的百分比与剩余工作中PTO小时数的百分比。基本上,我可以使用该应用程序来快速查看我是否在整个一年中都烧毁了自己分配的带薪时间。这就是我到目前为止的情况,

using System;
using System.Globalization;
using System.Linq;
class Program
{
static void Main()
{
    int PTOHoursTotal = 144;
    int PTOleft = 91;//user inputs the number of PTO hours remaining
    int workdays = 366;//the for loop below will run through the entire year and deduct 
    //holidays and weekends from 366 to give the total number of workdays in the year 
    var Holidays = new[]
    {
        "February 17,2020","May 25,"July 3,"September 7,"October 12,"November 11,"November 26,"December 25,2020"
    }.Select(str => DateTime.ParseExact(str,"MMMM d,yyyy",CultureInfo.InvariantCulture));
    for (DateTime i = DateTime(2020,1,1); i < (2020,12,31); i.AddDays(1))
    {
        if (Holidays.Contains(i) || i.DayOfWeek == Saturday || i.DayOfWeek == Sunday)
        {
            workdays--;
        }
        Console.WriteLine(workdays);
    }
}

我相当确定我的for循环出了点问题,最重要的是,如果有人可以展示一种将假日字符串的声明列表从字符串转换为日期时间的方法,那将不胜感激。根据某个日期计算网站,最终的工作日数应为251。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)