What is the right way to pass class parameters to a method

Posted by Schneider on Stack Overflow See other posts from Stack Overflow or by Schneider
Published on 2013-11-07T09:51:04Z Indexed on 2013/11/07 9:53 UTC
Read the original article Hit count: 170

Filed under:
|
|
|

Let's suppose I have three classes A, B and C

public class A
{
    public int A1;
    public string A2;
}

public class B
{
    public char B1;
    public double B2;
    public decimal B3;
}

public class C
{
    public string DoSomething(A a, B b)
    {
        var a1 = a.A1;
        var b2 = b.B2;
        var b3 = b.B3;

        // DoSomething

        return string.Empty;
    }
}

If DoSomething() is using just some fields of the A and B classes, do you prefer to pass the whole object in parameters or create an intermediate class that has just the needed fields by the DoSomething method ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about class