TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jessica Green
NA
9
0
Serialization, Deserialization Exception
Apr 30 2008 9:40 PM
I have to make this assignment:
Visit this link for the JPG of the assignment so you know what exactly I'm supposed to do..
http://i25.tinypic.com/21owwg5.jpg
I've done much of the program but I keep getting an unhandled exception when i run it.
Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace HomeWork_2
{
public abstract class Person
{
public abstract string Name { set; get; }
public abstract string PhoneNumber { set; get; }
public virtual void PrintInfo() { ;}
}
class PersonInfo : Person
{
private string personName;
private string phoneNumber;
public PersonInfo() { }
public override string Name
{
set
{
personName = value;
}
get
{
return personName;
}
}
public override string PhoneNumber
{
set
{
phoneNumber = value;
}
get
{
return phoneNumber;
}
}
public override void PrintInfo()
{
Console.WriteLine("Name: {0} \nPhoneNumber: {1}", personName, PhoneNumber);
}
}
class Program
{
static void Main(string[] args)
{
bool quit = false;
PersonInfo empInfo = new PersonInfo();
PersonInfo[] info = new PersonInfo[10];
try
{
using (Stream input = File.OpenRead("membership.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
info = (PersonInfo[])bf.Deserialize(input);
}
}
catch (FileNotFoundException)
{
}
while (!quit)
{
Console.Write(" Main Menu\n\t(1) Add \n\t(2) Search \n\t(3) Print All \n\t(4) Exit\n\t-> ");
int option = Int32.Parse(Console.ReadLine());
switch (option)
{
case
1:
Console.Write("\nEnter Employee name: ");
empInfo.Name = Console.ReadLine();
Console.Write("\nEnter the employee's phone #: ");
empInfo.PhoneNumber = Console.ReadLine();
break;
case
2:
Console.WriteLine("Enter the name of the employee whose record you want to find\n-> ");
empInfo.Name = Console.ReadLine();
if (empInfo.Equals(empInfo))
{
Console.WriteLine("Record Found");
}
else
Console.WriteLine("Record not found...");
break;
case
3:
break;
case
4:
using (Stream output = File.Create("membership.dat"))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(output, empInfo);
}
quit = true;
break;
}
}
}
}
}
Reply
Answers (
6
)
FTP to HTTPS
how write a stredprocedure to get the date from 1st jan to tilldate