随笔分类 -  常用算法

摘要:一、引言枚举为我看日常开发的可读性提供的非常好的支持,但是有时我们需要得到枚举值得描述信息或者是注释(备注)信息比如要获得TestEmun.aaa 属性值得备注 AAA,比较不方便得到。 public enum TestEmun { /// AAA aaa =1, /// BBB bbb =2, /// CCC ccc =3 }如果要得到类似的效果,我们就需要修改一下代码了,使用反射很容易得到这个结果。二、定义特性using System;using System.Reflection;namespace Lib.DataModel.SysEnum{ /// <s... 阅读全文
posted @ 2013-01-30 16:43 草青工作室 阅读(756) 评论(0) 推荐(0)
摘要:使用 .net 自带的方法 TrimEnd(char[]) 也可以删除,但是有些情况不是我们想要的结果如:source =bx20x0x0x0;delStr = x0;source =source.TrimEnd("x0".ToArry());这时 source 的值为:bx2;其实我们的预期是,想得到bx20 值。上面多删除了一个 0。解决方案:重写一个 TrimEnd 扩展 /// <summary> /// 在字符串尾部删除重复的指定字符串 /// </summary> /// <returns></returns> p 阅读全文
posted @ 2012-12-12 20:10 草青工作室 阅读(190) 评论(0) 推荐(0)
摘要:Dictionary<string, string> dic1 = new Dictionary<string, string>(); dic1.Add("ddd","123"); dic1.Add("aaa", "123"); dic1.Add("ccc", "123"); dic1.Add("fff", "123"); dic1.Add("eee", "123"); d 阅读全文
posted @ 2012-09-21 20:39 草青工作室 阅读(1703) 评论(0) 推荐(0)
摘要:使用 C# lamda 表达式写的两种递归函数//将一个平行数据,整理为一个树形数据private void Test1(List<myType> allTypeList){ //查找父节点List<myType> rootType = allTypeList.Where(o => o.ParentId == -1).ToList(); //递归主函数Action<myType> addChildType = null;addChildType= (typeInfo => { var childInfo = allTypeList.Where(o 阅读全文
posted @ 2012-08-16 15:49 草青工作室 阅读(399) 评论(0) 推荐(0)
摘要:在 stream流 和 byte[] 中查找(搜索)指定字符串这里注重看的是两个 Search 的扩展方法,一个是 stream类型的扩展,另一个是 byte[] 类型的扩展,如果大家有更好的“算法”,请给回复,我们一起优化!-- 常用扩展代码,需要这部分代码的支持!using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Drawing;namespace Ims.Bll{ /// <summary> /// stre 阅读全文
posted @ 2012-04-26 14:02 草青工作室 阅读(274) 评论(0) 推荐(0)
摘要:count = len(len-1)/narr={1,2,3}len=3n=2组合的个数 count = len(len-1)/2 = 3(3-1)/2 =3----------------------得到的组合结果为1,21,32,3----------------------using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Testing{ class Program { static void Main(string[] args) { TestDoubl 阅读全文
posted @ 2012-02-03 11:41 草青工作室 阅读(641) 评论(0) 推荐(0)