Charles Baldo
asked on
must declare a body because it is not marked abstract or extern
Hi I am a newbie and am getting this error when trying to learn xml serialization
Error 1 'XMLSerialize.Movie.Title. get' must declare a body because it is not marked abstract or extern C:\XMLSerializer\XMLSerial izer\Progr am.c
I have attached the code snippet, could anyone please tell me why and what to do to fix?
Thank You
Error 1 'XMLSerialize.Movie.Title.
I have attached the code snippet, could anyone please tell me why and what to do to fix?
Thank You
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace XMLSerialize
{
public class MainClass
{
static void Main(string[] args)
{
Movie movie = new Movie();
movie.Title = "Starship Troopers";
movie.ReleaseDate = DateTime.Parse("11/7/1997");
movie.Rating = 6.9f;
SerializeToXML(movie);
}
static public void SerializeToXML(Movie movie)
{
XmlSerializer serializer = new XmlSerializer(typeof(Movie));
TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
serializer.Serialize(textWriter, movie);
textWriter.Close();
}
}
public class Movie
{
public string Title
{
get; set;
}
public int Rating
{ get; set; }
public DateTime ReleaseDate
{ get; set; }
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well that's what I get for using VS .Net 3.5. Snarf0001 is correct about auto-implemented properties. ;==)
ASKER
thanks a ton Snarf0001, Thanks fernando as well as catching data type mismatch
initialize all your strings else they will not be serialized on serialization if the members are null