您好,登錄后才能下訂單哦!
本篇文章為大家展示了 靜態(tài)類(lèi)在c#中使用場(chǎng)景有哪些,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
comm類(lèi)就是靜態(tài)的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轉(zhuǎn)換為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; } }
上述內(nèi)容就是 靜態(tài)類(lèi)在c#中使用場(chǎng)景有哪些,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。