我得到了“缺失论据”在可选变量上 [英] I'm getting "argument missing" on optional variables

查看:65
本文介绍了我得到了“缺失论据”在可选变量上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



ok首先请不要讨厌,我不是那么好哈哈,



我的问题我会尝试解释它很简单,

我有一个看起来像这样的课程



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

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

CURRENCYListUtils.populateCurrencyList(cboCUR, dtCURRENCY, true, false,,, true);





在vb我仍然能够对此,但在C#中似乎它不喜欢它,我不知道如何正确地说出这个问题,因为我不知道他们会称这个过程,基本上我只是想通过发送一些参数,但是不是所有的,只有一些,所以请那些知道我想要实现的人,请帮助



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

推荐答案

这是VB的正确语法但不适用于C#



参数全部按顺序出现,除非为其命名



试试这个:



This is correct syntax for VB but not for C#

The parameters all appear in order unless you name them

Try this:

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





在此示例中,除了最后一个参数之外,所有未命名的参数都在参数列表中。这被命名为它在序列中的位置是无关紧要的。编译器在includeNone之后看到参数有序列表停止因此使用默认值。



PS:您可以命名任何参数,以便您可以按照您喜欢的任何顺序添加它们有助于提高可读性话虽这么说,在两个实例中命名参数是有用的:

1:在上面描述的参数顺序被中断的情况下

2:在创建匿名类时linq查询





希望有所帮助^ _ ^

Andy



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


这篇关于我得到了“缺失论据”在可选变量上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆