将命名参数与常规参数混合

时间:2017-11-14 08:26:30

标签: vb.net visual-studio

当我尝试调用这样的函数时:

> dput(test)
structure(list(transaction_type = structure(4L, .Label = c("10", 
"11", "15", "20", "21", "25"), class = "factor"), entry_type = 
structure(13L, .Label = c("AMER", 
"ARC", "BOC", "CCD", "CIE", "CTX", "DISC", "EFT", "JCB", "MAST", 
"POP", "POS", "PPD", "RCK", "TEL", "VISA", "WEB"), class = "factor"), 
qty = 391L, total_amount = 10212.13, sic = structure(12L, .Label = c("4900", 
"5047", "6012", "6300", "6513", "7372", "7393", "7399", "7997", 
"8099", "8351", "8931", "8999", "9311", "9399"), class = "factor"), 
markettype = structure(1L, .Label = c("0", "1", "2", "3", 
"4"), class = "factor"), Average_Amnt = 26.1179795396419), .Names = 
c("transaction_type", 
"entry_type", "qty", "total_amount", "sic", "markettype", "Average_Amnt"
), row.names = c(NA, -1L), spec = structure(list(cols = structure(list(
location_id = structure(list(), class = c("collector_integer", 
"collector")), settle_date = structure(list(format = ""), .Names = "format", 
class = c("collector_date", 
"collector")), transaction_type = structure(list(), class = 
c("collector_integer", 
"collector")), entry_type = structure(list(), class = 
c("collector_character", 
"collector")), response_code = structure(list(), class = 
c("collector_character", 
"collector")), funding_type = structure(list(), class = 
c("collector_character", 
"collector")), qty = structure(list(), class = c("collector_integer", 
"collector")), service_fee = structure(list(), class = c("collector_skip", 
"collector")), total_amount = structure(list(), class = 
c("collector_double", 
"collector")), organization_id = structure(list(), class = 
c("collector_skip", 
"collector")), status = structure(list(), class = c("collector_character", 
"collector")), sic = structure(list(), class = c("collector_integer", 
"collector")), markettype = structure(list(), class = c("collector_integer", 
"collector")), isoid = structure(list(), class = c("collector_skip", 
"collector")), city = structure(list(), class = c("collector_skip", 
"collector")), StateProvince = structure(list(), class = 
c("collector_character", 
"collector")), postalcode = structure(list(), class = c("collector_skip", 
"collector")), CreateDate = structure(list(format = ""), .Names = "format", 
class = c("collector_datetime", 
"collector")), DeleteDate = structure(list(), class = c("collector_skip", 
"collector"))), .Names = c("location_id", "settle_date", 
"transaction_type", "entry_type", "response_code", "funding_type", 
"qty", "service_fee", "total_amount", "organization_id", "status", 
"sic", "markettype", "isoid", "city", "StateProvince", "postalcode", 
"CreateDate", "DeleteDate")), default = structure(list(), class = 
c("collector_guess", 
"collector"))), .Names = c("cols", "default"), class = "col_spec"), class = 
c("tbl_df", 
"tbl", "data.frame"))

但是使用像这样的命名参数:

Columns.AddColumn("Caption", "U_Fam_ItmsGrpCod", 20, False)

编译器弹出错误,期望命名所有参数。换句话说,它强迫我命名所有参数,或者不命名它们。有没有办法混合这两种使用函数参数的方法?例如,从6中命名2个参数。

此外,有没有办法自动命名与Visual Studio兼容的VB.NET参数?

谢谢。

1 个答案:

答案 0 :(得分:4)

在按Passing Arguments by Position and by Name in VB.NET中的名称和位置混合参数时,您应该注意这个解释:

  

当您通过位置和名称的混合提供参数时,   位置论证必须首先出现。 提供参数后   按名称,其余参数必须全部按名称

因此,此分配不正确:

Columns.AddColumn(Caption := "Caption", Field := "U_Fam_ItmsGrpCod", 20, False)

正确的方法是从第一个位置提供所有参数作为命名参数,如下例所示:

Columns.AddColumn(Caption := "Caption", Field := "U_Fam_ItmsGrpCod", OtherArgument1 := 20, OtherArgument2 := False)

或者您可以省略两个第一个参数的命名参数,并为剩余的参数分配命名参数:

Columns.AddColumn("Caption", "U_Fam_ItmsGrpCod", OtherArgument1 := 20, OtherArgument2 := False)