您好,登錄后才能下訂單哦!
本篇文章為大家展示了 靜態類在c#中使用場景有哪些,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
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<HttpResponseMessage>.Run<HttpResponseMessage>(() => { 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; } /// <summary> /// datetime轉換為unixtime /// </summary> /// <param name="time"></param> /// <returns></returns> 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<string> 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#中使用場景有哪些,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。