i have data structure i am passing this from server to client using data contract.
the data structure is
class datatransfer
{
double m_value1;
double m_value2;
double m_value3;
};
in the client i want to write into file.
- The idea is to convert the values of the data transfer into string using string builder
than transfer the string to the client.
or
- send the data structure and write the file using stream writer
which is the best approach? converting to string or send the datastructure and write to the file?
Reason for the question: to avoid the generation of string.
double size is 8 bytes. If i convert it to string what will be the size allocated .
It depends entirely on how you format the
Stringrepresentation of theDouble. There is no pre-defined sizing guideline.For example:
Note that the sizes are the result of a
Charbeing 2 bytes on my system.What you’re really trying to do is called serialization. There’s a number of ways to do this. The simplest of which may be to just decorate your class with the
[Serializable]attribute:You’ll need to make your member variables
public, or provide publicly accessible properties for setting the member variables. Otherwise they will not be serialized using this approach.