boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - 新手请教问题
相关主题
serialization problem
C# interview question
.net 2003竟然不支持类中静态变量
好像c#为了DotNet牺牲了不少
请教:Asp.net如何给jq class 赋值
求救一个小问题
小菜鸟求助,PDF header signature not found
Q: c# datetime nullable objects
C# DateTime to Oracle Date
add web service
相关话题的讨论汇总
话题: movie话题: using话题: public话题: textwriter
进入DotNet版参与讨论
1 (共1页)
o**********a
发帖数: 330
1
刚接触 xml,为什么第一段code 可以work。 而第2段code不能正确地创建xml
多谢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace xmlapp
{

public class Movie
{
public string Title
{ get; set; }
public int Rating
{ get; set; }
public DateTime ReleaseDate
{ get; set; }
}
class Program
{
static void Main(string[] args)
{

Movie movie = new Movie();
movie.Title = "Starship Troopers";
movie.ReleaseDate = DateTime.Parse("11/7/1997");
movie.Rating = (int)6.9f;
SerializeToXML(movie);
}
static public void SerializeToXML(Movie movie)
{
XmlSerializer serializer = new XmlSerializer(typeof(Movie));
TextWriter textWriter = new StreamWriter(@"d:\movie.xml");
serializer.Serialize(textWriter, movie);
textWriter.Close();
}
}
}
///////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace xmlapp
{
public class Movie
{
readonly string title;
public string Title
{ get {return title;} }
readonly int rating;
public int Rating
{ get { return rating; } }
readonly DateTime releaseDate;
public DateTime ReleaseDate
{ get {return releaseDate;} }
public Movie(string title, int rating, DateTime releaseDate)
{
this.title = title;
this.rating = rating;
this.releaseDate = releaseDate;
}
public Movie() { }
}

class Program
{
static void Main(string[] args)
{

DateTime rd = DateTime.Parse("11/7/1997");
Movie movie = new Movie("hello", 34, rd);
SerializeToXML(movie);
}
static public void SerializeToXML(Movie movie)
{
XmlSerializer serializer = new XmlSerializer(typeof(Movie));
TextWriter textWriter = new StreamWriter(@"d:\movie.xml");
serializer.Serialize(textWriter, movie);
textWriter.Close();
}
}
}
k****i
发帖数: 1072
2
Need to have setter when using xmlserializer. Use DataContractSerializer
instead.

【在 o**********a 的大作中提到】
: 刚接触 xml,为什么第一段code 可以work。 而第2段code不能正确地创建xml
: 多谢
: using System;
: using System.Collections.Generic;
: using System.Linq;
: using System.Text;
: using System.Xml.Serialization;
: using System.IO;
: namespace xmlapp
: {

1 (共1页)
进入DotNet版参与讨论
相关主题
add web service
我的第一个小C#程序
请教 pass by value or reference 的问题
C#版ruby太慢了
[转载] free VB .NET
做CONTRACT的市场价?
刚发现youtube上出现好多full movie
有时候感觉美国人就是吃饱了撑的
我党有钱了,为啥不暗中资助一些亲共的西方媒体?
在看Starship Troopers,觉得里面的制度挺好
相关话题的讨论汇总
话题: movie话题: using话题: public话题: textwriter