开发者

C# Generics: 'x' is a 'type' but used like a 'variable'

开发者 https://www.devze.com 2023-01-24 15:18 出处:网络
For some reason, this code won\'t compile: JsonSerializer serializer = new JsonSerializer(); _sectionStories = 开发者_如何学Pythonserializer.Deserialize < IDictionary<int, ObservableCollection&

For some reason, this code won't compile:

JsonSerializer serializer = new JsonSerializer();
_sectionStories = 开发者_如何学Pythonserializer.Deserialize < IDictionary<int, ObservableCollection<Story>>(new JTokenReader(contents));

The error:

Error 91 'System.Collections.Generic.IDictionary>' is a 'type' but is used like a 'variable'

What am I doing wrong here? I feel like I'm missing something basic.


Looks like a typo. I see three < but only two >.


You are missing a >.

For illustrative purposes, I have matched up the <s and >s below:

_sectionStories = serializer.Deserialize<
                     IDictionary<
                        int,
                        ObservableCollection<Story>
                     >
                  >(new JTokenReader(contents)));


i think the good synthaxe is :

JsonSerializer serializer = new JsonSerializer();
        _sectionStories = serializer.Deserialize < IDictionary<int, ObservableCollection<Story>>>(new JTokenReader(contents)); 
0

精彩评论

暂无评论...
验证码 换一张
取 消