C# not inferring overloaded method via return type

前端 未结 6 1708
我在风中等你
我在风中等你 2021-01-21 05:17

I\'m writing a C# programlet to crawl a directory and give me a listing of files whose date in the last CSV line is less than the current date. Since this is a programlet, I\'m

6条回答
  •  庸人自扰
    2021-01-21 05:56

    There is always a way to hammer it into place, unfortunately:

    class Program
    {
        static void Main(string[] args)
        {
            object stringDate = "";
            object dateTime = new DateTime();
            DateUtils.DateStringGetter(ref stringDate);
            DateUtils.DateStringGetter(ref dateTime);
        }
    }
    
    public static class DateUtils
    {
        private static DateTime DateStringConverter(string mmddyyyy, char delim = '/')
        {
            string[] date = mmddyyyy.Split(delim);
            DateTime fileTime = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]),
                Convert.ToInt32(date[1]));
            return fileTime;
        }
    
        public static void DateStringGetter(ref object date)
        {
            string sYear = DateTime.Now.Year.ToString();
            string sMonth = DateTime.Now.Month.ToString().PadLeft(2, '0');
            string sDay = DateTime.Now.Day.ToString().PadLeft(2, '0');
    
            if (date is String)
            {
                date = sMonth + '/' + sDay + '/' + sYear;
            }
    
            if (date is DateTime)
            {
                date = DateStringConverter(sMonth + '/' + sDay + '/' + sYear);
            }
    
        }
    }
    

提交回复
热议问题