471,627 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Converting instances to byte[]

Hi,

I have the following class, and I will be creating instances of it to
transfer it over a networkstream. Now I need to convert instances p1,
p2 and p3 to byte[].

How can I do this?

Can someone help me out
Thanks in Advance

Person p1 = ("MyName", "MySurname");
Person p2 = ("MySurname");
Person p3 = ("MyName");

public class Person
{
private string name, surname;

public Person(){}
public Person(string n) {Name = n;}
public Person(string s) {Surname = s;}
public Person(string n, string s)
{
Name= n;
Surname = s;
}

public string Name
{
set {name = value;}
get { return name;}
}

public string Surname
{
set {surname = value;}
get {return surname;}
}
}

Feb 12 '06 #1
2 1188
Problem was solved, using BinaryFormatter

Feb 12 '06 #2
Curious wrote:
Hi,

I have the following class, and I will be creating instances of it to
transfer it over a networkstream. Now I need to convert instances p1,
p2 and p3 to byte[].

How can I do this?


Have a look at the BinaryFormatter and the XmlSerializer classes. The
BinaryFormatter creates a binary stream of your objects, the
XmlSerializer creates XML from your objects, which you can send over the
network as well.

hth,
Max
Feb 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by matt melton | last post: by
4 posts views Thread by Hal Vaughan | last post: by
11 posts views Thread by Chris Online | last post: by
4 posts views Thread by Ciaran | last post: by
10 posts views Thread by JT | last post: by
3 posts views Thread by news.microsoft.com | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.