Linq 高级应用实例
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization; namespace ConsoleApplication1
{
public class Program
{
public static void Main(string[] args)
{
StreamReader sr = new StreamReader(@"C:\Users\UserAccount\Desktop\20131103203219.txt");
string record = string.Empty; StringBuilder sb = new StringBuilder();
sb.Append('[');
while ((record = sr.ReadLine()) != null)
{
sb.Append(record + ',');
}
sb.Remove(sb.ToString().Length - , );
sb.Append(']'); JavaScriptSerializer js = new JavaScriptSerializer();
List<GPS> list = js.Deserialize(sb.ToString(), typeof(List<GPS>)) as List<GPS>; var list2 = from x in list
where x.Distance % < && x.SpeedMeter !=
orderby x.GPSTime ascending
select new { x.DuringTime, x.Distance, x.SpeedMeter }; // 求在起点处几个点的平均速度
var list3 = from x in list2
orderby (int)x.Distance / ascending
group x by (int)x.Distance / into gx
select new
{
gx.Key,
Distance = gx.Min(p => p.Distance),
Speed = gx.Average(p => p.SpeedMeter)
}; // 求每一圈的平均速度
var list4 = from x in list
where x.SpeedMeter !=
group x by (int)(x.Distance / ) into gx
orderby gx.Key ascending
select new
{
gx.Key,
Distance = gx.Min(p => p.Distance),
Speed = gx.Average(p => p.SpeedMeter)
}; StreamWriter sw = new StreamWriter(@"T:\kongston.txt");
foreach (var g in list4)
{
sw.WriteLine(js.Serialize(g));
Console.WriteLine(js.Serialize(g));
} sr.Close();
sw.Close();
sr.Dispose();
sw.Dispose();
}
}
} GPS类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ConsoleApplication1
{
public class GPS
{
public double Longitude { get; set; } public double Latitude { get; set; } public double Accuracy { get; set; } public double Altitude { get; set; } public double SpeedMeter { get; set; } private long _GPSTime; public long GPSTime
{
get
{
return this._GPSTime;
}
set
{
this._GPSTime = value; // C# 解析GPS返回的时间
DateTime dt = new DateTime(, , ).AddMilliseconds(value).AddHours();
NormalTime = dt;
StringTime = dt.ToString("yyyy-MM-dd HH:mm:ss");
}
} public DateTime NormalTime { get; set; } public string StringTime { get; set; } public double Bearing { get; set; } public int DuringTime { get; set; } public double Distance { get; set; }
}
}
Linq 高级应用实例的更多相关文章
- Webform(Linq高级查、分页、组合查询)
一.linq高级查 1.模糊查(包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r => ...
- 使用LINQ查询数据实例和理解
使用LINQ查询数据实例和理解 var contacts= from customer in db.Customers where customer.Name.StartsWith("A&q ...
- LinQ高级查询、组合查询、IQueryable集合类型
LinQ高级查询: 1.模糊查询(包含) Repeater1.DataSource = con.car.Where(r =>r.name.Contains(s)).ToList(); 2.开头 ...
- Linq高级查询,分页查询及查询分页结合
一.高级查询与分页查询 1.以...开头 StartsWith Repeater1.DataSource=con.Users.Where(r=>r.Nickname.StartsWith( ...
- 2017年12月14日 LinQ高级查&&Asp.net WebForm Asp.net MVC
LinQ的高级查询用法 开头:StartsWith()结尾:EndsWith()模糊:Contains() 个数:Count最大值:Max(r => r.price)最小值:Min(r => ...
- LinQ 高级查询
高级查询 模糊查(包含):.Contains(name) 开头:.StartsWith(name) 结尾:.EndsWith(name) 个数:.Count() 最大值:Max(r => r.p ...
- [C#]Linq To Xml 实例操作- 转
http://blog.sina.com.cn/s/blog_6c762bb301010oi5.html http://blog.xuite.net/cppbuilder/blog/9940157 在 ...
- LinQ综合应用实例
直接上代码,内容很浅显易懂,在这里就不做更多的解释,解释见代码注释. using System; using System.Collections.Generic; using System.Linq ...
- LINQ高级编程 笔记
相关资料:http://www.cnblogs.com/lifepoem/archive/2011/12/16/2288017.html 1.什么是LINQ 语言集成查询是一系列标准查询操作符的集合, ...
随机推荐
- HDU-6703 array
Description You are given an array a1,a2,...,an(∀i∈[1,n],1≤ai≤n). Initially, each element of the arr ...
- andriod工程项目总结
1,胡萝卜农场项目 (1)图片缓存项目 (2)android开源框架的尝试 2,智能厨房项目 (1)将所有网络请求防止到一个service中的思路 (2)左右导航的实现 (3)fragment的使用 ...
- 与Pig相似,Hive是一种MapReduce上的抽象工具(除非使用新的执行引擎)
Hive隐藏了后面的MapReduce任务 EXPLAIN sql: 分析查询计划.
- Django中间件添加白名单
一定记得配置 补充一点中间件是工作流程 中间件的详细流程 补充一点需求:在不用中间件的情况和下用装饰器做登陆的阻挡 在django中有自带的 登陆闭包函数只需要引出来就可以直接用了下面是步骤 在se ...
- 十九、python内置函数汇总
'''内置函数abs():取绝对值all():每个元素都为真,才是真any():有一个元素为真即为真bin():十进制转二进制hex():十进制转十六进制int():所有的转成十进制oct():十进制 ...
- 四、robotframework生成几种随机数
1.random()生成0<=n<1之间的随机实数--它会生成一个随机的浮点数,范围是在0.0~1.0之间.: ${num} evaluate random.random() ra ...
- 用Vue来实现音乐播放器(八):自动轮播图啊
slider.vue组件的模板部分 <template> <div class="slider" ref="slider"> <d ...
- ubuntu 安装java1.8
1.进入官网下载页面http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.选择需要的版本,进入下载页面 下载 jdk ...
- MVC 源码系列之控制器执行(二)
## 控制器的执行 上一节说道Controller中的ActionInvoker.InvokeAction public virtual bool InvokeAction(ControllerCon ...
- 从新向你学习javase(第一天)
1:阐述JDK和JRE之间区别 jdk(工具)>jre(运行环境)>jvm(虚拟机) 2: 能够使用常见的DOS命令 d:(进入D盘下),cd +路径(进入到当前路径),cd..(返回上一 ...