2

I need to serialize and send someone a file. There are two types of struct which I will deal with, one is called trade and one is called quote. I am trying to nest them inside the class tickdata but I don't seem to get it.

public class tickdata
{
    public class trade
    {
        long time;
        double price;
        uint size;
    }
    public class quote
    {
        long time;
        double bid;
        double ask;
        double bidsize;
        double asksize;
    }
}
3
  • 1
    Why don't you create the 2 classes Trade and Quote and give TickData 2 members, one of type Trade and one of Quote? Commented Mar 11, 2014 at 9:36
  • that a good suggestion. Thanks I will do it Commented Mar 11, 2014 at 9:36
  • Did my answer helped you? Then please accept. If not, do you have further questions? Commented Mar 14, 2014 at 10:40

1 Answer 1

1

Do it like this

public class tickdata
{
private Trade trade;
private Quote quote;
}

public class trade
{
long time;
double price;
uint size;
        }

    public class quote
    {
        long time;
        double bid;
        double ask;
        double bidsize;
        double asksize;
    }

Read more about http://en.wikipedia.org/wiki/Object_composition and http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)

This is not C#-Specific, it is important for Object-Orientation at all

Sign up to request clarification or add additional context in comments.

4 Comments

But why fields are private?
Provide setter and getter for the fields. Objects should not expose their fields directly to their environement. Read about en.wikipedia.org/wiki/…
it's can be done like public Trade trade {get; set;}
Sorry, I'm coming from a Java Background :-) Do it like this, as it is the C#-Way. But keep the information-hiding in mind every time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.