欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實現(xiàn)一個相當全面的數(shù)據(jù)轉(zhuǎn)換工具類

 更新時間:2025年03月06日 10:29:17   作者:WangMing_X  
這篇文章主要為大家介紹了如何使用C#編寫一個通用工具類DataConvert來進行數(shù)據(jù)轉(zhuǎn)換,包括30+個數(shù)據(jù)類型轉(zhuǎn)換,需要的可以了解一下

C#通用工具類DataConvert,作為靜態(tài)類全局可調(diào)用,來進行數(shù)據(jù)轉(zhuǎn)換。包括byte[]轉(zhuǎn)數(shù)字、CSV、數(shù)字轉(zhuǎn)byte[]、16進制數(shù)轉(zhuǎn)換、TryParse、DateTime等。

一、具體函數(shù)列表

default部分函數(shù)

//default
 
public static string ArrayToString<T>(T[] array)
public static string ListToString<T>(List<T> list)

byte[]轉(zhuǎn)數(shù)字部分函數(shù)

//byte[]轉(zhuǎn)數(shù)字
 
/// <summary>
/// byte數(shù)組中取int數(shù)值,本方法適用于(低位在前,高位在后)的順序
/// </summary>
/// <param name="src">byte數(shù)組 </param>
/// <param name="offset"> 從數(shù)組的第offset位開始 </param>
/// <returns>int數(shù)值</returns>
public static int BytesToInt32(byte[] src, int offset)
 
/// <summary>
///  byte數(shù)組中取int數(shù)值,本方法適用于(低位在后,高位在前)的順序
/// </summary>
/// <param name="src"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static int BytesToInt32R(byte[] src, int offset)
 
/// <summary>
/// byte數(shù)組中取short數(shù)值,本方法適用于(低位在前,高位在后)的順序
/// </summary>
/// <param name="src"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static short BytesToInt16(byte[] src, int offset)
 
/// <summary>
/// byte數(shù)組中取short數(shù)值,本方法適用于(低位在后,高位在前)的順序
/// </summary>
/// <param name="src"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static short BytesToInt16R(byte[] src, int offset)

數(shù)字轉(zhuǎn)byte[]部分函數(shù)

/// <summary>
/// Int16轉(zhuǎn)換成byte[] (低位在前,高位在后)的順序
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
public static byte[] Int16ToBytes(short num)
 
/// <summary>
/// Int16轉(zhuǎn)換成byte[] (低位在后,高位在前)的順序
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
public static byte[] Int16ToBytesR(short num)
 
/// <summary>
/// Int32轉(zhuǎn)換成byte[] (低位在前,高位在后)的順序
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
 public static byte[] Int32ToBytes(int num)
 
/// <summary>
/// Int32轉(zhuǎn)換成byte[] (低位在后,高位在前)的順序
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
public static byte[] Int32ToBytesR(int num)
 

16進制數(shù)轉(zhuǎn)換部分函數(shù)

public static string byteArrayToHexString(byte[] data)
 
public static byte[] StrToHexBytes(string hexString)
 
 /// <summary>
 /// "03E8"→1000
 /// </summary>
 /// <param name="hex"></param>
 /// <returns></returns>
 public static int HexToDecimal(string hex)
 

TryParse部分函數(shù)

public static bool BoolTryParse(string str, ref bool value)
 
public static bool ByteTryParse(string str, ref byte value)
 
public static bool ShortTryParse(string str, ref short value)
 
public static bool UshortTryParse(string str, ref ushort value)
 
public static bool IntTryParse(string str, ref int value)
 
public static bool FloatTryParse(string str, ref float value)
 
public static bool DoubleTryParse(string str, ref double value)
 
public static bool EnumTryParse<T>(string str, ref T value)

DateTime部分函數(shù)

 private static readonly DateTime
 /// <summary>
 /// DateTime轉(zhuǎn)10位時間戳
 /// </summary>
 /// <param name="dateTime"></par
 /// <returns></returns>
public static long DateTimeToTimeStamp10(DateTime dateTime)
 
/// <summary>
/// DateTime轉(zhuǎn)13位時間戳
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static long DateTimeToTimeStamp13(DateTime dateTime)
 
/// <summary>
/// 10位時間戳轉(zhuǎn)DateTime
/// </summary>
/// <param name=”timeStamp”></param>
/// <returns></returns>
public static DateTime TimeStamp10ToDateTime(long timeStamp)
 
/// <summary>
/// 13位時間戳轉(zhuǎn)DateTime
/// </summary>
/// <param name=”timeStamp”></param>
/// <returns></returns>
public static DateTime TimeStamp13ToDateTime(long timeStamp)
 

二、函數(shù)調(diào)用示例

1、引用DataConvert類的命名空間(或修改類文件的命名空間為當前項目)

2、在引用了DataConvert命名空間的項目里面直接用類名點出內(nèi)部的轉(zhuǎn)換函數(shù)

int rssi= DataConvert.HexToDecimal(“C3”);

以上就是C#實現(xiàn)一個相當全面的數(shù)據(jù)轉(zhuǎn)換工具類的詳細內(nèi)容,更多關于C#數(shù)據(jù)轉(zhuǎn)換的資料請關注腳本之家其它相關文章!

相關文章

  • C#獲取項目指定目錄下文件的方法

    C#獲取項目指定目錄下文件的方法

    這篇文章主要介紹了C#獲取項目指定目錄下文件的方法,涉及C#操作目錄及文件的技巧,非常具有實用價值,需要的朋友可以參考下
    2015-04-04
  • 簡單對比C#程序中的單線程與多線程設計

    簡單對比C#程序中的單線程與多線程設計

    這篇文章主要介紹了C#程序中的單線程與多線程設計的簡單對比,通過實際的代碼演示可以清晰看出多線程并發(fā)來避免單線程阻塞問題的特點,需要的朋友可以參考下
    2016-04-04
  • c#多線程通信之委托事件

    c#多線程通信之委托事件

    這篇文章主要介紹了c#多線程通信之委托事件,對多線程感興趣的同學可以參考下
    2021-04-04
  • C#之lock的使用及說明

    C#之lock的使用及說明

    這篇文章主要介紹了C#之lock的使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • Unity?百度AI實現(xiàn)Logo商標識別

    Unity?百度AI實現(xiàn)Logo商標識別

    本文主要介紹了Unity實現(xiàn)檢測和識別圖片中的品牌LOGO信息。即對于輸入的一張圖片(可正常解碼,且長寬比適宜),輸出圖片中LOGO的名稱、位置和置信度。需要的可以參考一下
    2022-01-01
  • C#中靜態(tài)構造函數(shù)的幾點說明介紹

    C#中靜態(tài)構造函數(shù)的幾點說明介紹

    本篇文章主要是對C#中靜態(tài)構造函數(shù)的幾點說明進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2014-01-01
  • 輕松學習C#的正則表達式

    輕松學習C#的正則表達式

    輕松學習C#的正則表達式,對C#的正則表達式感興趣的朋友可以參考本篇文章,幫助大家更靈活的運用C#的正則表達式
    2015-11-11
  • Unity3D 計時器的實現(xiàn)代碼(三種寫法總結)

    Unity3D 計時器的實現(xiàn)代碼(三種寫法總結)

    這篇文章主要介紹了Unity3D 計時器的實現(xiàn)代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • C#?PaddleOCRSharp?OCR進行疲勞測試

    C#?PaddleOCRSharp?OCR進行疲勞測試

    PaddleOCRSharp?是百度飛槳封裝的.NET版本?OCR?dll?類庫,OCR可以將圖像文件中的文本內(nèi)容進行識別,下面我們就來看看如何通過它們實現(xiàn)疲勞測試吧
    2024-11-11
  • C# WinForm控件對透明圖片重疊時出現(xiàn)圖片不透明的簡單解決方法

    C# WinForm控件對透明圖片重疊時出現(xiàn)圖片不透明的簡單解決方法

    這篇文章主要介紹了C# WinForm控件對透明圖片重疊時出現(xiàn)圖片不透明的簡單解決方法,結合實例形式分析了WinForm圖片重疊后造成圖片不透明的原因與相應的解決方法,需要的朋友可以參考下
    2016-06-06

最新評論