1

I am getting an error thrown when the text box value is null, so I was trying to write a ternary statement to check if the value is null. This is what I cam up with:

DrawTextValuePair(e, string.IsNullOrEmpty(m_pcl.pn.Text) ? String.Format("Input: ", m_pcl.pn.Text) : String.Format("Input: "), true, m_leftMargin);

But in using such I get a compile error of:

There is no argument given that corresponds to the required formal parameter 'iLeftMargin' of 'ProfileDocument.DrawTextValuePair(PrintPageEventArgs, string, string, bool, int)'

What would be the proper way to utilize a ternary statement in this instance?

Yohan Greenburg
  • 333
  • 1
  • 3
  • 9

1 Answers1

2

The method

ProfileDocument.DrawTextValuePair(PrintPageEventArgs, string, string, bool, int)

expects 5 arguments, but you provided it with only 4:

DrawTextValuePair(
    e, // 1st
    string.IsNullOrEmpty(m_pcl.pn.Text) ? String.Format("Input: ", m_pcl.pn.Text) : String.Format("Input: "), // 2nd
    true, // 3rd
    m_leftMargin // 4th
);
Dmitry
  • 13,797
  • 6
  • 32
  • 48
  • hah, so nothing is wrong with my ternary statement, just providing the wrong number of arguments! – Yohan Greenburg Aug 28 '17 at 18:06
  • @YohanGreenburg Exactly! That's why the error message tells that. :p – Dmitry Aug 28 '17 at 18:08
  • @Dmitry No offence but code can be simplified. Second string format is redundant. Shouldn't we keep to good practices and when we using string alias once than keep to it everywhere? I know the string thing is just meather of coding standard but still...? – Krzysztof Lach Aug 28 '17 at 18:24
  • @KrzysztofLa I agree, but how it relates to the topic? – Dmitry Aug 28 '17 at 18:41
  • @Dmitry It is not. It was btw your good answer. I always thought it matters to keep with good practices when reviewing someone's code. But whatever. End of topic. – Krzysztof Lach Aug 28 '17 at 18:50
  • 1
    @KrzysztofLa I agree, code review is very important part of the development. This is why code review is always welcome here: [codereview.stackexchange.com](https://codereview.stackexchange.com/). You could participate. :p – Dmitry Aug 28 '17 at 19:01