using System.Net; internal class Program { private static void Main(string[] args) { //组成字符串 var m1 = string.Concat(1, 2,3,4,121); //判断是否有空格的字符串 string.IsNullOrWhiteSpace(" "); string i1 ="abc";string i2 = "ABC"; //比较结果0是相等 int r1 = string.Compare(i1, i2,ignoreCase:true); //百分比 var a = (decimal)5; var b = 3; var c = (a / b).ToString("p"); //时间戳转时间 var t1 = StampToDateTime("1686037513000"); //url转成base64 var result = GetUrlToBase64(@"http://59.249.230.64:80/group1/M00/9B/66/O_nmQGR-5T2AGYEeAAKraJLaWBc10.jpeg"); //发布环境才走 #if !DEBUG var ttt = "ssss"; #endif //分组去每组最大的积分 var customerList = new List<Customer>{ new Customer {Name = "a", Score =30}, new Customer {Name = "a", Score =35}, new Customer {Name = "b", Score =20}, new Customer {Name = "c", Score =50}, new Customer {Name = "b", Score =60}, new Customer {Name = "a", Score =80}, }; List<Customer> customers = customerList .GroupBy(t => t.Name).SelectMany(a => a.Where(b => b.Score == a.Max(c => c.Score))).ToList(); foreach (var data in customers) { Console.WriteLine(data.Name + "," + data.Score); } Console.ReadLine(); } /// <summary> /// 获取网络图片转换为base64 /// </summary> /// <param name="url">网络图片路径 例:http://123.123.123.123/a.jpg</param> /// <returns></returns> public static (bool, string) GetUrlToBase64(string url) { try { WebClient mywebclient = new WebClient(); byte[] Bytes = mywebclient.DownloadData(url); string Base64string = Convert.ToBase64String(Bytes); return (true, Base64string); } catch (Exception e) { return (false, null); } } /// <summary> /// 时间戳转时间带毫秒 /// </summary> /// <param name="timeStamp"></param> /// <returns></returns> public static DateTime StampToDateTime(string timeStamp) { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(timeStamp + "0000"); TimeSpan toNow = new TimeSpan(lTime); return dtStart.Add(toNow); } } public class Customer { public string Name; public int Score; }
标签:Customer,功能,string,c#,基础,Score,var,new,Name From: https://www.cnblogs.com/elsons/p/17504467.html