如何从中检索int值List是最大数,但仍小于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#中的代码有问题,如果有人可以帮我解决我的问题.
在函数中,我正在解析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) 我有一个解析方法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) 这是我的清单:
var MaxItemCountFromRegItems = RegisteredItems.MyRegisteredItems
.Where(s => s.ItemID == _itemID)
.Sum(s => s.Posted);`
Run Code Online (Sandbox Code Playgroud)
它失败并出现错误:
异常:System.ArgumentNullException:值不能为null.
它的明显错误发生是因为收集是空的.我想知道如何避免它.