新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#操作內(nèi)存讀寫方法淺析
C#操作內(nèi)存讀寫方法是什么呢?讓我們來看看具體的實(shí)例實(shí)現(xiàn):

伊美網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),伊美網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為伊美上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的伊美做網(wǎng)站的公司定做!
- using System.Runtime.InteropServices;
- using System.Text;
- public class Function
- {
- //C#操作內(nèi)存讀寫方法
- public static byte PtrToByte( int Ptr )
- {
- byte b = Marshal.ReadByte( ( IntPtr ) Ptr );
- return b;
- }
- public static char PtrToChar( int Ptr )
- {
- byte b = Marshal.ReadByte( ( IntPtr ) Ptr );
- return ( char ) b;
- }
- public static short PtrToShort( int Ptr )
- {
- short b = Marshal.ReadInt16( ( IntPtr ) Ptr );
- return b;
- }
- //C#操作內(nèi)存讀寫方法
- public static ushort PtrToUShort( int Ptr )
- {
- ushort b = ( ushort ) Marshal.ReadInt16( ( IntPtr ) Ptr );
- return b;
- }
- public static int PtrToInt( int Ptr )
- {
- int b = Marshal.ReadInt32( ( IntPtr ) Ptr );
- return b;
- }
- public static uint PtrToUInt( int Ptr )
- {
- uint b = ( uint ) Marshal.ReadInt32( ( IntPtr ) Ptr );
- return b;
- }
- public static long PtrToLong( int Ptr )
- {
- long b = Marshal.ReadInt64( ( IntPtr ) Ptr );
- return b;
- } //C#操作內(nèi)存讀寫方法
- public static ulong PtrToULong( int Ptr )
- {
- ulong b = ( ulong ) Marshal.ReadInt64( ( IntPtr ) Ptr );
- return b;
- }
- // Convert an ip address stored an address to equivalent string value
- public static string GetPtrToIpAddr(int intPtr, int varlen)
- {
- int i = 0;
- StringBuilder sb = new StringBuilder(0,varlen*4);
- byte[] byx = new byte[varlen];
- // ip address cann't have zero value C#操作內(nèi)存讀寫方法
- // ip address cann't have zero length C#操作內(nèi)存讀寫方法
- if( ( intPtr == 0 ) || ( varlen == 0 ) ) return "";
- Marshal.Copy( ( IntPtr ) intPtr , byx , 0 , varlen );
- for( i = 0; i < varlen - 1; i ++ )
- {
- sb.Append(byx[i]);
- sb.Append('.');
- }
- sb.Append(byx[varlen - 1]);
- return sb.ToString();
- }
- }
C#操作內(nèi)存讀寫方法的基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#操作內(nèi)存讀寫方法有所幫助。
分享名稱:C#操作內(nèi)存讀寫方法淺析
URL地址:http://m.fisionsoft.com.cn/article/dpdgpeh.html


咨詢
建站咨詢
