Why do I need to call the ToList() method on my LINQ query?
For example:
private void btnEnc_Click(object sender, RoutedEventArgs e)
{
SHA1 sha = new SHA1Managed();
string sResult = "";
var v = sha.ComputeHash(
UTF8Encoding.Unicode.GetBytes(tbxWordToEncrypt.Text)
).Select(
p => sResult += string.Format("{0:x2}", p)
).ToList();
Clipboard.SetText(sResult);
tbxEncrypted.Text = sResult;
}
Also, when I try to access the clipboard I get a security dialog box. How can I prevent this?

The reason that you need to call to list is because the expression inside the Select isn’t evaluated until the expression created by the LINQ statement is evaluated. Because you’re using it to append to
sResult, that variable won’t have had its value changed before you put it on the clipboard unless you “run” the LINQ expression using ToList(). Note that the output of ToList() is basically worthless.The bigger problem is that you’re misusing the Select. You really should be using string.Join instead of building the string inside the Select clause. Building it inside the Select clause is going to be unexpected for people reading your code and harder to understand.