小编riv*_*riv的帖子

C#如何按具有相同属性值的对象对List进行分组

假设我有以下对象

 public class DepartmentSchema
{
    public int Parent { get; set; }
    public int Child { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我有List<DepartmentSchema>以下结果:

Parent | Child
---------------
  4    |   1
  8    |   4
  5    |   7
  4    |   2
  8    |   4
  4    |   1
Run Code Online (Sandbox Code Playgroud)

我想对所有具有相同父值和子值的对象进行分组 分组后我想要的结果是以下列表

 Parent | Child
---------------
  4    |   1
  8    |   4
  5    |   7
  4    |   2
Run Code Online (Sandbox Code Playgroud)

我成功使用 IGrouping =>

departmentSchema.GroupBy(x => new { x.Parent, x.Child }).ToList();

但结果List<IGrouping<'a,DepartmentSchema>>不是List<DepartmentSchema>

我知道我可以创建一个新的 foreach 循环并 …

c# linq

2
推荐指数
1
解决办法
2784
查看次数

c#AES解密希伯来字母显示为问号

我有一个包含希伯来字母的字符串,
在我打算解密加密字符串后,所有希伯来字母都显示为问号(如 - > ??? ?? ??????)

这些是我用来加密和解密的两种方法

 public static string Encrypt(string dectypted)
    {
        byte[] textbytes = ASCIIEncoding.ASCII.GetBytes(dectypted);
        AesCryptoServiceProvider encdec = new AesCryptoServiceProvider();
        encdec.BlockSize = 128;
        encdec.KeySize = 256;
        encdec.Key = ASCIIEncoding.ASCII.GetBytes(Key);
        encdec.IV = ASCIIEncoding.ASCII.GetBytes(IV);
        encdec.Padding = PaddingMode.PKCS7;
        encdec.Mode = CipherMode.CBC;

        ICryptoTransform icrypt = encdec.CreateEncryptor(encdec.Key, encdec.IV);

        byte[] enc = icrypt.TransformFinalBlock(textbytes, 0, textbytes.Length);
        icrypt.Dispose();

        return Convert.ToBase64String(enc) + Key;
    }

    public static string Decrypt(string enctypted)
    {
        byte[] encbytes = Convert.FromBase64String(enctypted);
        AesCryptoServiceProvider encdec = new AesCryptoServiceProvider();
        encdec.BlockSize = 128;
        encdec.KeySize = 256;
        encdec.Key …
Run Code Online (Sandbox Code Playgroud)

c# encryption

0
推荐指数
1
解决办法
89
查看次数

标签 统计

c# ×2

encryption ×1

linq ×1