本篇文章為大家展示了 靜態(tài)類在c#中使用場(chǎng)景有哪些,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

comm類就是靜態(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)類在c#中使用場(chǎng)景有哪些,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當(dāng)前文章:靜態(tài)類在c#中使用場(chǎng)景有哪些-創(chuàng)新互聯(lián)
瀏覽路徑:http://chinadenli.net/article42/egjhc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站改版、品牌網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容