-1

I have the next data:

for each post I have id-s that likes the post.

for example:

post: "Hi"
"12345"
"11111"
"22222"
"33333"

post: "bye"
"16666"
"77777"
"12345"
"33333"

etc

I defined the next variables:

Dictionary<string, LikesDistribution> IdsToLikesDistribution;

and the class:

public class LikesDistribution {
    public int counter;
    public List<string> posts;
}

I want to count the total likes and the posts that each of the user likes.

for the above example:

"12345" 2 "Hi" "Bye"
"11111" 1 "Hi"
"22222" 1 "Hi"
"33333" 2 "Hi" "Bye"
"16666" 1 "Bye"
"77777" 1 "Bye"

if my dictionary was from Id to number of likes:

Dictionary<string, int> IdsToLikesDistribution;

I could do something like:

int value;
// if it doesn't exist
if (!IdsToLikesDistribution.TryGetValue(fanId, out value))
{
    IdsToLikesDistribution.Add(fanId, 1);
}
// it exists so increase it by 1
else
{
    IdsToLikesDistribution[fanId] = value + 1;
}

but now I don't know how to do it.

any help appreciated!

4

1 回答 1

1

看来您想知道的是如何设置/读取 Class 属性。

根据我对您的解释的理解,IdsToLikesDistribution[fanId]返回 Class 的一个实例LikesDistribution

如果是这种情况,您可以调用IdsToLikesDistribution[fanId].counter以获取该counter值并按照您将 Id 映射到喜欢的数量时的方式使用它。

同样,IdsToLikesDistribution[fanId].posts将返回用户喜欢的帖子列表,您可以将新/旧帖子附加或删除到列表中。

让我知道我是否可以进一步澄清!

于 2013-08-29T23:43:51.653 回答