随笔分类 -  实例应用,通用方法

摘要:1 /// <summary> 2 /// 经纬度转换为弧度 3 /// </summary> 4 /// <param name="d">经度/纬度</param> 5 /// <returns></returns> 6 private static double Rad(double d) 7 阅读全文
posted @ 2023-04-21 15:13 llkj 阅读(576) 评论(0) 推荐(0)
摘要:private bool TryIp(string ipaddress) { string[] ip = new string[4]; string s = "."; ip = ipaddress.Split(s.ToCharArray(), 4); if (ip.Length < 4) { ret 阅读全文
posted @ 2020-11-30 17:02 llkj 阅读(392) 评论(0) 推荐(0)
摘要:1 private int SubstringCount(string str, string a) 2 { 3 int count = 0; 4 if (str.Contains(a)) 5 { 6 string s = str.Replace(a, ""); 7 count = str.Leng 阅读全文
posted @ 2020-11-24 10:31 llkj 阅读(346) 评论(0) 推荐(0)
摘要:方法:递归 数据结构:队列 输入:要删除的最高级别的项 利用递归的方法,迭代查找要删除的项 是否满足 其子项也被删除或无子项, 满足则入队列,否则将队列置为空,逐层返回。 阅读全文
posted @ 2020-11-23 17:08 llkj 阅读(110) 评论(0) 推荐(0)
摘要:public byte[] IntToByteArray(int src, int length) { byte[] b = new byte[length]; for (int i = 0; i < length; i++) { b[length - i - 1] = (byte)((src >> 阅读全文
posted @ 2020-10-30 17:24 llkj 阅读(211) 评论(0) 推荐(0)
摘要:byte数组转换为int byte[] bytes = {0xff, 0xff}; int num = BitConverter.ToInt32(bytes, 0); // 0为字节数组开始转换的起始位置下标 int 转换为 byte数组 int num = 3; byte[] bytes = Bi 阅读全文
posted @ 2020-10-30 17:05 llkj 阅读(2278) 评论(0) 推荐(0)
摘要:int 类型的变量要转换为定长的字符串, 不足的位置用指定字符补齐。 1. 数字左对齐。字符串尾部补0 例:int 转换为长度为8的字符串,不足的位置在字符串末尾用 ‘0’ 补齐。 int num = 4; string snum = num.ToString().PadRight(8, '0'); 阅读全文
posted @ 2020-10-22 09:18 llkj 阅读(2909) 评论(0) 推荐(0)
摘要://将字节转换成字符串(16进制) // 方法1 public string Bytes2HexString(byte[] bytes) { string str= ""; for (int i = 0; i < bytes.Length; i++) { str += string.Format(" 阅读全文
posted @ 2020-08-20 11:15 llkj 阅读(456) 评论(0) 推荐(0)
摘要://将十进制数字转换成字节数组 //由数字创建字节数组 public byte[] DecimalToByteArray(decimal src) { //创建内存流 MemoryStream stream 作为存放二进制数据的缓存 using (MemoryStream stream = new 阅读全文
posted @ 2020-08-20 09:48 llkj 阅读(1278) 评论(0) 推荐(0)