将日期时间添加到枚举 [英] Add datetime to enum

查看:207
本文介绍了将日期时间添加到枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下枚举,相应地读取文本文件。我需要对文件做的是从文本文件名解析日期,以便我可以通过我的数据库检查它的记录。如何设置每个文件读取日期?



我尝试过:



I have the following Enum that reads a text file accordingly. What I need to do with the file is parse the date from the textfile name so I can check records for it through my database. How do I set the each file to read through the date?

What I have tried:

public enum FileType
        {
            Customer, Account, Transaction
        }







public FileTypeInfo(FileType type, int ssnesPos, int idPos, string name)
               : this()
           {
               Type = type;
               SSNesPosition = ssnesPos;
               CustIDPosition = idPos;
               Name = name;
           }







FileInfo = new Dictionary<FileType, FileTypeInfo>();

            FileInfo[FileType.Customer] = new FileTypeInfo(FileType.Customer, 3, -1, "Customers");
            FileInfo[FileType.Account] = new FileTypeInfo(FileType.Account, -1, 1, "Accounts");
            FileInfo[FileType.Transaction] = new FileTypeInfo(FileType.Transaction, -1, 1, "Transactions");
string names = "";
            foreach (var f in FileInfo)
            {
                names += f.Value.Name + ", ";
            }
            names = names.Remove(names.Length - 2);
            Log.Info("Found configuration information for " + FileInfo.Count + " types of file: " + names + ".");
        }

推荐答案

如果你需要上次写文件的日期:



If you need the date the file was last written:

DateTime fileTime = File.GetLastWriteTime(filename);


这篇关于将日期时间添加到枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆