0

在我正在解析的 XML 中,我有以下内容:

<event>
    <book>Felicity Fly</book>
    <author>Christina Gabbitas</author>
    <bookImgUrl>http://www.whsmith.co.uk/Images/Products\957\255\9780957255203_t_f.jpg</bookImgUrl>
    <info>Christina Gabbitas will be signing copies of her new book, Felicity Fly. Books should be bought from WHSmith. Proof of purchase may be necessary</info>
    <date>20 Apr 2013</date>
    <startTime>10:30</startTime>
    <location>
        <name>WHSmith Chester</name>
        <address>5-7 Foregate Street</address>
        <city>Chester</city>
        <county>Cheshire</county>
        <postcode>CH1 1HH</postcode>
        <tel>01244 321106</tel>
    </location>
</event>

我想从两个节点 <date>和创建一个 DateTime 对象<startTime>。所以我这样做:

var EventEntity = new Event()
{
    Book = e.Book,
    BookImgUrl = e.BookImgUrl,
    Info = e.Info,
    Start = new DateTime().**?**
};

但是当我在 DateTime 对象之后按点 [.] 时,我没有从 Intellisense 获取 Parse 方法,这是为什么呢?我究竟做错了什么?

我正计划使用这篇文章中概述的解决方案。

4

1 回答 1

1

Parse 是一个静态方法,但您调用它是因为它是一个实例方法。你应该这样称呼它:

var EventEntity = new Event()
{
    Book = e.Book,
    BookImgUrl = e.BookImgUrl,
    Info = e.Info,
    Start = DateTime.ParseExact(...) // or DateTime.TryParseExact(...)
};
于 2013-04-12T11:51:09.603 回答