我需要比较两个日期时间值以确定相等(完全相同),使用精确度.这是最好的方法吗?我的日期可能有几秒和几毫秒,但我想只考虑到几分钟.
where (Math.Abs(datetime1.Subtract(datetime2).TotalMinutes) == 0)
Run Code Online (Sandbox Code Playgroud) 我正在使用c#.NET 4.0编写Windows服务(我的开发工作站是Windows 7).目的是在处理过程中出现错误时直接从服务发送电子邮件.我已经包含了一个代码片段来展示我想要实现的目标:
try
{
string emailAddresses = "me@sample.com";
string emailCCAddresses = "you@sample.com";
//Send the email
using (MailMessage mailMsg = new MailMessage())
{
mailMsg.To.Add(emailAddresses);
mailMsg.From = new MailAddress("winService@sample.com");
mailMsg.CC.Add(emailCCAddresses);
mailMsg.Subject = " Error Message ";
mailMsg.Body = DateTime.Now + " : Invalid File Encountered." ;
////Creating the file attachment
using (Attachment data = new Attachment("C:\\users\\sample.xml", MediaTypeNames.Application.Octet))
{
//Add timestamp info for the file
ContentDisposition disposition = data.ContentDisposition;
disposition.ModificationDate = File.GetLastWriteTime("C:\\users\\sample.xml");
mailMsg.Attachments.Add(data);
SmtpClient emailClient = new SmtpClient("example.Sample.com", 25);
emailClient.DeliveryMethod = SmtpDeliveryMethod.Network; …Run Code Online (Sandbox Code Playgroud)