静态类在c#中使用场景有哪些-创新互联
本篇文章为大家展示了 静态类在c#中使用场景有哪些,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
创新互联建站始终坚持【策划先行,效果至上】的经营理念,通过多达10年累计超上千家客户的网站建设总结了一套系统有效的营销推广解决方案,现已广泛运用于各行各业的客户,其中包括:门窗定制等企业,备受客户赞誉。comm类就是静态的Static
public class fnComm { public static JObject Post(HttpClient myhttp, string url, JObject json) { HttpContent content = new StringContent(JsonConvert.SerializeObject(json), Encoding.UTF8, "application/json"); var message = Task.Run (() => { return myhttp.PostAsync(url, content); }); message.Wait(); //接收返回得信息 if (message.Result.IsSuccessStatusCode) { var s = Task.Run(() => { return message.Result.Content.ReadAsStringAsync(); }); s.Wait(); return JObject.Parse(s.Result); } else { throw new Exception("StatusCode:" + message.Result.StatusCode.ToString()); } } public static byte[] ConvertToByteAry(object obj) { var j = JsonConvert.SerializeObject(obj); var ary = System.Text.Encoding.UTF8.GetBytes(j); return ary; } /// /// datetime转换为unixtime /// /// ///public static int TimeToUnixTime(System.DateTime time) { return (int)(time - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds; } public static string GenerateTransId(int i) { string transId = DateTime.Now.ToString("yyyyMMddHHmmss"); int l = i - 14; return transId + CreateRandCode(l); } public static string CreateRandCode(int codeLen) { string codeSerial = "1,2,3,4,5,6,7,a,c,d,e,f,h,i,j,k,m,n,p,r,s,t,A,C,D,E,F,G,H,J,K,M,N,P,Q,R,S,U,V,W,X,Y,Z"; if (codeLen == 0) { codeLen = 16; } string[] arr = codeSerial.Split(','); string code = ""; int randValue = -1; Random rand = new Random(unchecked((int)DateTime.Now.Ticks)); for (int i = 0; i < codeLen; i++) { randValue = rand.Next(0, arr.Length - 1); code += arr[randValue]; } return code; } public static string GetStringFromList(List list) { StringBuilder sb = new StringBuilder(); string strReturn; if (list.Count > 0) { foreach (string item in list) { sb.AppendFormat("'{0}',", item); } strReturn = sb.ToString(0, sb.Length - 1); } else { strReturn = "''"; } return strReturn; } }
上述内容就是 静态类在c#中使用场景有哪些,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
分享文章:静态类在c#中使用场景有哪些-创新互联
URL链接:http://azwzsj.com/article/egjhc.html