小编Tag*_*eit的帖子

列表中的最大值小于X.

如何从中检索intList是最大数,但仍小于X我所比较的值.

Value = 10

Example one: List = {1,4,6,8};  => number 8 biggest on list and smaller than 10
Example two: List = {1,15,17,20}; => number 1 biggest on list and smaller than 10
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用Linq但到目前为止没有成功.

c# linq

4
推荐指数
1
解决办法
2185
查看次数

不能在匿名方法中使用ref或out参数

我在c#中的代码有问题,如果有人可以帮我解决我的问题.

在函数中,我正在解析Xml文件并将其保存到结构中.

然后我尝试从具有特定节点ID的所述结构中检索一些信息,并且我的代码失败了

"不能在匿名方法,lambda表达式或查询表达式中使用ref或out参数'c'"

这是我的代码:

public void XmlParser(ref Point a, ref Point b, ref Point c)
{
     XDocument xdoc = XDocument.Load(XmlDirPath); 
     var coordinates = from r in xdoc.Descendants("move")
                        where int.Parse(r.Attribute("id").Value) == c.NodeID  // !! here is the error !!
                        select new
                        {
                              X = r.Element("x").Value,
                              Y = r.Element("y").Value,
                              Z = r.Element("z").Value, 
                              nID = r.Attribute("id").Value
                         };

     foreach (var r in coordinates)
     {
          c.x = float.Parse(r.X1, CultureInfo.InvariantCulture);
          c.y = float.Parse(r.Y1, CultureInfo.InvariantCulture);
          c.z = float.Parse(r.Z1, CultureInfo.InvariantCulture);
          c.NodeID = Convert.ToInt16(r.nID);
     }
}

public struct …
Run Code Online (Sandbox Code Playgroud)

c# xml lambda

3
推荐指数
2
解决办法
8376
查看次数

按属性重新匹配对象列表

我有一个解析方法XML:

public static List<Profile> Parse XML(string Document)
{
    List<Profile> Result = new List<Profile>();     
    doc = XDocument.Load(Document);

    Resoults = (from n in doc.Descendants("level")
               select new Profile()
               {
                   CurrentID = int.Parse(n.Attribute("CurrentID").Value),    
                   Location = (from l in n.Element("ID").Elements("ID")
                              select new Location()
                              {
                                   id = (int)(l.Attribute("id")),
                                   x = (Single)l.Attribute("x"),
                                   y = (Single)l.Attribute("y"),
                                   z = (Single)l.Attribute("z")
                              }).ToList(),    
                   Bank = (from l in doc.Descendants("Banker")
                              select new Banker()
                              {
                                   BankID = (int)(l.Attribute("id")),
                                   BankX = (Single)(l.Attribute("x")),
                                   BankY = (Single)(l.Attribute("y")),
                                   BankZ = (Single)(l.Attribute("z"))
                              }).ToList(),    
                   Vendor = (from …
Run Code Online (Sandbox Code Playgroud)

c# list

3
推荐指数
1
解决办法
54
查看次数

总和在空列表上失败

这是我的清单:

var MaxItemCountFromRegItems = RegisteredItems.MyRegisteredItems
                                              .Where(s => s.ItemID == _itemID)
                                              .Sum(s => s.Posted);`
Run Code Online (Sandbox Code Playgroud)

它失败并出现错误:

异常:System.ArgumentNullException:值不能为null.

它的明显错误发生是因为收集是空的.我想知道如何避免它.

c# linq

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

标签 统计

c# ×4

linq ×2

lambda ×1

list ×1

xml ×1