Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi guys,

ok firstly please don't hate, im not that good lol,

My problem i will try to explain it simple,
I have a class that looks like this

C#
public static void populateCurrencyList(ComboBox cbo,
                                         DataTable dtCURR,
                                         bool includeAll = false,
                                         bool includeNone = false,
                                         bool ACTIVE_Only = false,
                                         bool DomesticCurrencyOnly = false,
                                         bool skipIfNoAgreement = false,
                                         bool excludeDomesticCURIfNotEnabled = false,
                                         string RUN = "",
                                         bool skipIfAgreementNotActive = false) {


And i am trying to use this class by doing this
C#
CURRENCYListUtils.populateCurrencyList(cboCUR, dtCURRENCY, true, false,,, true);


In vb i was still able to this , but in C# it seems like it doesn't like it, I dont have an idea how to phrase this question correctly because i have no idea what they would call this process, basically i just want to send some arguments through, but not for all of them, only some, so please to those guys that have an idea of what i want to achieve, please help
Posted

1 solution

This is correct syntax for VB but not for C#

The parameters all appear in order unless you name them

Try this:

C#
CURRENCYListUtils.populateCurrencyList(cboCUR, dtCURRENCY, true, false,  skipIfNoAgreement: true);


In this example, all of the unnamed parameters are in the parameter list order except the last. This is named so it's position in the sequence is irrelevant. The compiler sees the parameter ordered list stop after includeNone so uses the default.

PS: you can name any parameters so you can add them in any order you like if it helps readability. That being said, it is only useful to name parameters in two instances:
1: In the case stated above where parameter order is interupted
2: When creating anonymous classes in linq queries


Hope that helps ^_^
Andy
 
Share this answer
 
Comments
Marcel Heijmans 15-Jul-15 5:36am    
@Andy Dude, your my hero man, thank you very much, i wish people like you could always answer my questions :D it works perfectly
Andy Lanng 15-Jul-15 5:53am    
Thanks, man. I do it because my ego loves this level of praise ^_^
Marcel Heijmans 15-Jul-15 7:58am    
hahahah shots :D
Sergey Alexandrovich Kryukov 15-Jul-15 7:30am    
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900