c# 判断某个数字在某个范围 ,如何做,

c# 判断某个数字在某个范围 ,如何做,
1、我目前有一个集合test,存储的是这样的:
key:1001 value:100000-199999
2、我现在有一个值是100001.我要根据这个值去查集合test中的key.所以就得去集合中的test的value去进行范围判断.然后返回key
本人菜鸟.
714320 1年前 已收到1个回答 举报

Silence依 幼苗

共回答了13个问题采纳率:92.3% 举报

你需要写出具体的【集合】的定义的代码才行.还有,没明白key:1001 value:100000-199999是什么意思.

1年前 追问

5

714320 举报

ϴġõġͼ

举报 Silence依

//using System.Linq;
static void Main(string[] args)
{
//Dictionary
Dictionary D = new Dictionary();
D.Add("1001", "100000-199999");
D.Add("1002", "200000-299999");
D.Add("1003", "300000-399999");
//int i=100001;//1001
int i = 399998;//1003
var d = D.First(x =>
Convert.ToInt64(x.Value.Split(new char[] { '-' })[0]) <= i &
Convert.ToInt64(x.Value.Split(new char[] { '-' })[1]) >= i
).Key;
Console.WriteLine(d);
Console.ReadLine();
}
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.044 s. - webmaster@yulucn.com