我想在00:00:00将DateTime属性设置为前一天.我不知道为什么DateTime.AddDays(-1)不起作用.或者为什么DateTime.AddTicks(-1)不起作用.首先应该这样做吗?
我有2个物体.每个对象都有DateTime字段ValidFrom,ValidTo.
编辑:下班回家后,我试图获得与业务对象行为相同的行为.下面是我试图复制它看起来如何工作的代码.当然这是在家工作但不工作.好消息是我得到了很好的答案,并且+1!=)
public class RuleValue
{
public DateTime ValidFrom, ValidTo;
public RuleValue(DateTime _validFrom, DateTime _validTo)
{
ValidFrom = _validFrom;
ValidTo = _validTo;
}
// oldObject.ValidFrom = 1900-01-01
// oldObject.ValidTo = 9999-12-31
// newObject.ValidFrom = 2010-03-22
// newObject.ValidTo = 9999-12-31
public void ChangeOldDate(RuleValue oldObject, RuleValue newObject)
{
/*
* 1: When first object (oldObject) have ValidTo set to SQL-server maxdate (9999-12-12 23:59:59 etc)
* I want to allow for a new object to be created
* 2: oldObject timespan ValidFrom-ValidTo …Run Code Online (Sandbox Code Playgroud) 我需要在C#和Linq中将这个XML复制到XML.除了正常的.NET之外,我不希望任何依赖于其他库.XML如下所示.
问题:我无法弄清楚如何打印这两行:
<?mso-application progid="Excel.Sheet"?>
<Data ss:Type="String">name</Data>
Run Code Online (Sandbox Code Playgroud)
完整的XML文档:
<?xml version="1.0" encoding="utf-8" ?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet">
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"></OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"></ExcelWorkbook>
<Worksheet ss:Name="Sheet 1">
<Table>
<Row>
<Cell>
<Data ss:Type="String">name</Data>
</Cell>
<Cell>
<Data ss:Type="String">status</Data>
</Cell>
</Row>
<Row>
<Cell>
<Data ss:Type="String">Niike2</Data>
</Cell>
<Cell>
<Data ss:Type="String">Enabled</Data>
</Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
Run Code Online (Sandbox Code Playgroud)
码:
XNamespace ns = "urn:schemas-microsoft-com:office:spreadsheet";
XDocument doc = new XDocument(
new XDeclaration("1.0", "UTF-8", string.Empty),
new XComment(String.Format("Exported: {0}", DateTime.Now)),
new XElement(ns + "Workbook",
new XAttribute(XNamespace.Xmlns + "xsi", …Run Code Online (Sandbox Code Playgroud) 创建对象时:
var customers = new Customers
{
Persons = new List<Person>
{
new Person { CustomId = "111" },
new Person { CustomId = "222" }
},
Organizations = new List<Organization>
{
new Organization { CustomId = "333" }
},
Keys = new HashSet<string> { "111", "222", "333" }
};
Run Code Online (Sandbox Code Playgroud)
我想更改Keys的初始化以使用Person [0] .CustomId,Person [1] .CustomId和Organization [0] .CustomId中的先前值.(不像这样的"111","222","333"硬编码)
在这种初始化中有没有一种简单的方法可以做到这一点?我可以在客户初始化后添加密钥,如下所示:
foreach (var person in customers.Persons)
{
customers.Keys.Add(person.CustomId);
}
foreach (var org in customers.Organizations)
{
customers.Keys.Add(org.CustomId);
}
Run Code Online (Sandbox Code Playgroud)
但我不能在与客户相同的初始化中从人员和组织属性创建密钥?