1

Possible Duplicate:
Good GetHashCode() override for List of Foo objects

I have List of Objects, Object has ID, FileName, Status(Enumerator), DateStamp, UserId.
Using Linq I filter List using UserId and send it to Web App.

I need to get some kind of Unique Id for filtered result and compare it next time to detect changes for current user. If new Object added for current user or property of existing object is changed Unique Id should be different.

I have tried to use code below to get Hash Code but hash code is different for every myList object even objects and object properties are the same. Any ideas please?

myList= _queueList.GetItems(p => p.User.Id == userId)
                  .OrderByDescending(p => p.DateStamp)
                  .ToList();

myList.GetHashCode()

I think you want to call the MyBase.AuthorizeCore.

So you want to change this line

Dim authorized = AuthorizeCore(httpContext)

to

Dim authorized = MyBase.AuthorizeCore(httpContext)
4

2 回答 2

1
var uniqueId = string.Join(",", myList.Select(x=>x.Id.ToString()).ToArray());

如果字符串很长,您可以生成一个 md5 或 sha1 并返回它。

于 2012-08-07T13:48:39.730 回答
1

您可以像这样利用内置密码学:

string hash = Convert.ToBase64String(
    new SHA1CryptoServiceProvider().ComputeHash(
        Encoding.UTF8.GetBytes(
            string.Join(":", myList.Select(obj => obj.Id.ToString()).ToArray()
        )));

Convert.ToBase64String()让它对网络友好(注意:如果你有很多记录,结果字符串可能会变得很长!)

于 2012-08-07T13:51:42.270 回答