Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以从其值(VB.Net)推断字典(字符串、字符串)?_Vb.net_C# To Vb.net - Fatal编程技术网

是否可以从其值(VB.Net)推断字典(字符串、字符串)?

是否可以从其值(VB.Net)推断字典(字符串、字符串)?,vb.net,c#-to-vb.net,Vb.net,C# To Vb.net,如果问题在术语上没有正确表达,请道歉。这种事情对我来说是相当新鲜的 我正在尝试将以下ASP.Net C#代码转换为VB.Net: context.Authentication.SignIn(new AuthenticationProperties { Dictionary = { { "foo", "bar" } } }, new ClaimsIdentity()); 将此VB.Net抛出,但它不会编译: context.Authentication.SignI

如果问题在术语上没有正确表达,请道歉。这种事情对我来说是相当新鲜的

我正在尝试将以下ASP.Net C#代码转换为VB.Net:

context.Authentication.SignIn(new AuthenticationProperties
{
    Dictionary = {
        { "foo", "bar" }
    }
}, new ClaimsIdentity());
将此VB.Net抛出,但它不会编译:

context.Authentication.SignIn(New AuthenticationProperties() With {
    .Dictionary = {{"foo", "bar"}}
}, New ClaimsIdentity())
BC30526属性“字典”为“只读”

所以我重写了它,它确实有效:

context.Authentication.SignIn(
    New AuthenticationProperties(
        New Dictionary(Of String, String) From {{"foo", "bar"}}), 
        New ClaimsIdentity())
虽然我对此很满意,但就我自己的理解而言,我想知道VB.Net是否支持任何方法来初始化该字典,而不明确声明为
字典(字符串,字符串)
?像是某种懒惰的推论

类似于

context.Authentication.SignIn(
    New AuthenticationProperties(
        New() From {{"foo", "bar"}}), 
        New ClaimsIdentity())

使用
GetType
怎么样?如果你也有一个构造类,你就可以这样做。使用
GetType
怎么样?如果你也有一个构造类,你就可以这样做。。