Question

Visual C# How to Program (6th Edition) chapter 17 problem 4 ?

Visual C# How to Program (6th Edition) chapter 17 problem 4 ?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Outputs will be like;

Code will be like:

using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
[Serializable]
class Student
{
public string firstName;
public String lastName;
public string id;
public string grade;
static void Main(string[] args)
{
Student obj = new Student();
obj.firstName="sam";
obj.lastName = "smith";
obj.id = "Data structures";
obj.grade = "a";

IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(@"D:Demo.txt", FileMode.Create, FileAccess.Write);

formatter.Serialize(stream, obj);
stream.Close();

stream = new FileStream(@"D:Demo.txt", FileMode.Open, FileAccess.Read);
Student NewObj = (Student)formatter.Deserialize(stream);

Console.WriteLine(NewObj.firstName);
Console.WriteLine(NewObj.lastName);
Console.WriteLine(NewObj.id);
Console.WriteLine(NewObj.grade);

Console.ReadKey();
}
}
}

Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again.

Add a comment
Know the answer?
Add Answer to:
Visual C# How to Program (6th Edition) chapter 17 problem 4 ?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT