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 语言集成查询是一系列标准查询操作符的集合, ...
 
随机推荐
- 放一道比较基础的LCA 的题目把 :CODEVS 2370 小机房的树
			
题目描述 Description 小机房有棵焕狗种的树,树上有N个节点,节点标号为0到N-1,有两只虫子名叫飘狗和大吉狗,分居在两个不同的节点上.有一天,他们想爬到一个节点上去搞基,但是作为两只虫子, ...
 - nginx修改默认运行80端口的方法
			
修改方法 很简单,修改nginx的配置文件, 对应的值,如图: 将其改为别的端口号,就可以了.
 - HTML To Word
			
一.源码特点 1.在一些实际的应用场景中,有用户需要将一批规范的资料网页保存为WORD文档以便离线传阅或用于其它需求.在此之前,使用了OFFICE组件来尝试完成此功能需求,但是效果都不尽如 ...
 - Json ignore on class level
			
Exclude all instances of a class from serialization in Newtonsoft.Json Every custom type can opt how ...
 - (转)IDataGridViewEditingControl 接口 作用
			
本文转载自:http://blog.csdn.net/zx13525079024/article/details/4814575 IDataGridViewEditingControl 接口 定义承载 ...
 - 熟练使用jquery ui  / easyui的各种组件设计网页界面
			
熟练使用jquery ui / easyui的各种组件设计网页界面
 - 爱好-超级IP:超级IP
			
ylbtech-爱好-超级IP:超级IP IP,是Intellectual Property的缩写,字面粗译为“知识产权”,特指具有长期生命力和商业价值的跨媒介内容运营.一个具有可开发价值的真正的I ...
 - python 设置开机启动脚本
			
1.创建python_auto.bat的快捷方式,放入启动项: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\ ...
 - 06 使用bbed修复update的数据--01
			
场景1 表t3 SQL> select * from t3; ID NAME ---------- -------------------- aaa bbbb SQL> update t3 ...
 - Newtonsoft.Json源码中的C#预处理指令
			
cs文件中包含以指令: #if !(NET35 || NET20 || PORTABLE40) 记事本打开[Newtonsoft.Json.Net20.csproj]可看到以下代码: <Defi ...