当前位置: 首页>>代码示例>>C#>>正文


C# System.Byte类代码示例

本文整理汇总了C#中System.Byte的典型用法代码示例。如果您正苦于以下问题:C# Byte类的具体用法?C# Byte怎么用?C# Byte使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Byte类属于System命名空间,在下文中一共展示了Byte类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: chatServer

        private void chatServer()
        {
            Boolean isListen = true;

            while (isListen)
            {
                Byte[] bytesFromClient = new Byte[2097152];
                int len = 0;
                try
                {
                    len = _userSocket.Receive(bytesFromClient);
                    byte[] receiveByte = new byte[len];
                    receiveByte = bytesFromClient;
                    Message.Message msg = Message.MessageHandle.deserialize(receiveByte);
                    _clientRoom.broadcast(msg);

                }
                catch (Exception e)
                {

                    isListen = false;
                    _clientRoom.removeUser(_userName);

                    _userSocket.Close();
                    _userSocket = null;
                    Debug.WriteLine(e);
                    Debug.WriteLine(_userName + "退出聊天");
                    LogService.LogError(e.ToString());

                }
            }
        }
开发者ID:Hsiny,项目名称:SocketServer,代码行数:32,代码来源:User.cs

示例2: TestKnownEnc

    static Boolean TestKnownEnc(Aes aes, Byte[] Key, Byte[] IV, Byte[] Plain, Byte[] Cipher)
    {

        Byte[]  CipherCalculated;
        
        Console.WriteLine("Encrypting the following bytes:");
        PrintByteArray(Plain);
        Console.WriteLine("With the following Key:");
        PrintByteArray(Key);
        Console.WriteLine("and IV:");
        PrintByteArray(IV);
 		Console.WriteLine("Expecting this ciphertext:");
		PrintByteArray(Cipher);        
        
        ICryptoTransform sse = aes.CreateEncryptor(Key, IV);
        MemoryStream 	ms = new MemoryStream();
        CryptoStream    cs = new CryptoStream(ms, sse, CryptoStreamMode.Write);
        cs.Write(Plain,0,Plain.Length);
        cs.FlushFinalBlock();
        CipherCalculated = ms.ToArray();
        cs.Close();

		Console.WriteLine("Computed this cyphertext:");
        PrintByteArray(CipherCalculated);
        

        if (!Compare(Cipher, CipherCalculated)) {
        	Console.WriteLine("ERROR: result is different from the expected");
        	return false;
        }
        
        Console.WriteLine("OK");
        return true;
    }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:34,代码来源:AESKnownEnc2.cs

示例3: StreamToByte

 public byte[] StreamToByte(System.IO.Stream Stream)
 {
     Int32 length = Stream.Length > Int32.MaxValue ? Int32.MaxValue : Convert.ToInt32(Stream.Length);
         Byte[] buffer = new Byte[length];
         Stream.Read(buffer, 0, length);
         return buffer;
 }
开发者ID:TIT-tech,项目名称:OPM_BO,代码行数:7,代码来源:Converter.cs

示例4: ContainsInvalidUTF8Bytes

 /// <summary>
 /// Checks if the bytes contains invalid UTF-8 bytes
 /// </summary>
 public static Boolean ContainsInvalidUTF8Bytes(Byte[] bytes)
 {
     Int32 bits = 0;
     Int32 i = 0, c = 0, b = 0;
     Int32 length = bytes.Length;
     for (i = 0; i < length; i++)
     {
         c = bytes[i];
         if (c > 128)
         {
             if ((c >= 254)) return true;
             else if (c >= 252) bits = 6;
             else if (c >= 248) bits = 5;
             else if (c >= 240) bits = 4;
             else if (c >= 224) bits = 3;
             else if (c >= 192) bits = 2;
             else return true;
             if ((i + bits) > length) return true;
             while (bits > 1)
             {
                 i++;
                 b = bytes[i];
                 if (b < 128 || b > 191) return true;
                 bits--;
             }
         }
     }
     return false;
 }
开发者ID:thecocce,项目名称:flashdevelop,代码行数:32,代码来源:FileHelper.cs

示例5: Main

 static void Main(string[] args)
 {
     Log.Info("WorldServer", "Starting...");
     if (!EasyServer.InitLog("World", "Configs/WorldLog.conf") || !EasyServer.InitConfig("Configs/World.xml", "World")) return;
     Port = EasyServer.GetConfValue<int>("World", "Address", "Port");
     IP1 = EasyServer.GetConfValue<Byte>("World", "Address", "IP1");
     IP2 = EasyServer.GetConfValue<Byte>("World", "Address", "IP2");
     IP3 = EasyServer.GetConfValue<Byte>("World", "Address", "IP3");
     IP4 = EasyServer.GetConfValue<Byte>("World", "Address", "IP4");
     if (!EasyServer.Listen<TcpServer>(Port, "ClientServer")) return;
     Database.Connection.connectionString = EasyServer.GetConfValue<String>("World", "Database", "ConnectionString");
     FileMgr = new FileManager();
     Password = EasyServer.GetConfValue<string>("World", "Lobby", "Password");
     WorldName = EasyServer.GetConfValue<string>("World", "ClientServer", "Name");
     ID = EasyServer.GetConfValue<Byte>("World", "ClientServer", "Id");
     Lobby = new Lobby.Client(EasyServer.GetConfValue<String>("World", "Lobby", "Ip"), EasyServer.GetConfValue<int>("World", "Lobby", "Port"));
     districtsListener = new Districts.Listener(EasyServer.GetConfValue<String>("World", "Districts", "Ip"), EasyServer.GetConfValue<int>("World", "Districts", "Port"));
     clients.Clear();
     Log.Enter();
     Console.WriteLine("For available console commands, type /commands");
     Log.Enter();
     bool done = false;
     while (!done)
     {
         string command;
         command = Console.ReadLine();
         ProccessCommand(command);
     }
     EasyServer.StartConsole();
 }
开发者ID:Ryderizm,项目名称:rAPB,代码行数:30,代码来源:Program.cs

示例6: Search

        public static string[] Search(String[] token, String txt, out Byte distance)
        {
            if (txt.Length > 0)
            {
                Byte bestKey = 255;
                SortedDictionary<Byte, List<string>> matches = new SortedDictionary<byte, List<string>>();
                Docking.Tools.ITextMetric tm = new Docking.Tools.Levenshtein(50);
                foreach(string s in token)
                {
                    Byte d = tm.distance(txt, s);
                    if (d <= bestKey) // ignore worse matches as previously found
                    {
                        bestKey = d;
                        List<string> values;
                        if (!matches.TryGetValue(d, out values))
                        {
                            values = new List<string>();
                            matches.Add(d, values);
                        }
                        if (!values.Contains(s))
                            values.Add(s);
                    }
                }

                if (matches.Count > 0)
                {
                    List<string> result = matches[bestKey];
                    distance = bestKey;
                    return result.ToArray();
                }
            }
            distance = 0;
            return null;
        }
开发者ID:Michael--,项目名称:DockingFramework,代码行数:34,代码来源:Levenshtein.cs

示例7: SignHash

        public Byte[] SignHash (Byte[] rgbHash, string str) {
            Contract.Requires(rgbHash != null);
            Contract.Requires(rgbHash.Length == 20);
            Contract.Requires(rgbHash.Length == 16);

          return default(Byte[]);
        }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:7,代码来源:System.Security.Cryptography.RSACryptoServiceProvider.cs

示例8: bin2CArray

        public static Byte[] bin2CArray(Byte[] inputData, UInt32 memberSizeInBytes)
        {
            StringBuilder cArraySB;
              UInt32 sizeSB = (((UInt32)inputData.Length)/memberSizeInBytes +1) * (memberSizeInBytes*2 + 4) + 30;

              cArraySB = new StringBuilder((Int32)sizeSB);

              switch(memberSizeInBytes)
              {
            case 1:
              bin2charArray(inputData,cArraySB);
              break;
            case 2:
              break;
            case 4:
              bin2uintArray(inputData,cArraySB);
              break;
            case 8:
              break;
            default:
              break;
              }

              return (new ASCIIEncoding()).GetBytes(cArraySB.ToString());
        }
开发者ID:sv99,项目名称:DVSDK,代码行数:25,代码来源:HexConv.cs

示例9: IntPtrCopy

		public static int IntPtrCopy(IntPtr source, Stream dest, int length)
		{
			var buffer = new Byte[length];
			Marshal.Copy(source, buffer, 0, length);
			dest.Write(buffer, 0, length);
			return length;
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:7,代码来源:RdcBufferTools.cs

示例10: Main

        static void Main(string[] args)
        {
            //AsyncReadOneFile();

            //AsyncReadMultiplyFiles();

            FileStream fs = new FileStream(@"../../Program.cs", FileMode.Open,
               FileAccess.Read, FileShare.Read, 1024,
               FileOptions.Asynchronous);

            Byte[] data = new Byte[100];

            IAsyncResult ar = fs.BeginRead(data, 0, data.Length, null, null);

            while (!ar.IsCompleted)
            {
                Console.WriteLine("Операция не завершена, ожидайте...");
                Thread.Sleep(10);
            }

            Int32 bytesRead = fs.EndRead(ar);

            fs.Close();

            Console.WriteLine("Количество считаных байт = {0}", bytesRead);
            Console.WriteLine(Encoding.UTF8.GetString(data).Remove(0, 1));
        }
开发者ID:xs2ranjeet,项目名称:13ns9-1spr,代码行数:27,代码来源:Program.cs

示例11: SendFileToPrinter

	public static bool SendFileToPrinter( string szPrinterName, string szFileName )
	{
		// Open the file.
		FileStream fs = new FileStream(szFileName, FileMode.Open);
		// Create a BinaryReader on the file.
		BinaryReader br = new BinaryReader(fs);
		// Dim an array of bytes big enough to hold the file's contents.
		Byte []bytes = new Byte[fs.Length];
		bool bSuccess = false;
		// Your unmanaged pointer.
		IntPtr pUnmanagedBytes = new IntPtr(0);
		int nLength;

		nLength = Convert.ToInt32(fs.Length);
		// Read the contents of the file into the array.
		bytes = br.ReadBytes( nLength );
		// Allocate some unmanaged memory for those bytes.
		pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
		// Copy the managed byte array into the unmanaged array.
		Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
		// Send the unmanaged bytes to the printer.
		bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
		// Free the unmanaged memory that you allocated earlier.
		Marshal.FreeCoTaskMem(pUnmanagedBytes);
		return bSuccess;
	}
开发者ID:marioricci,项目名称:erp-luma,代码行数:26,代码来源:Class2.cs

示例12: PrintHEX

        /// <summary>
        /// Print a nice visual of the Buffer starting at offset.
        /// </summary>
        /// <param name="buffer">Buffer.</param>
        /// <param name="Offset">Offset.</param>
        public static void PrintHEX(Byte[] buffer,
                                    int Offset = 0) {
            Console.WriteLine(" 0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F | Text    ");
            Console.WriteLine("------------------------------------------------|---------");
            int count = 0, cur = 0;
            String left = "", right = "";
            foreach (byte b in buffer) {
                if (cur >= Offset) {
                    if (count >= 16) {
                        Console.WriteLine("{0}| {1}", left, right);

                        left = "";
                        right = "";
                        count = 0;
                    }

                    left += String.Format("{0:x2} ", b);
                    if (b >= 32 && b <= 255)
                        right += (char)b;
                    else
                        right += ".";

                    count++;
                } else
                    cur++;
            }

            if (count > 0)
                Console.WriteLine("{0}| {1}", left.PadRight(48), right);
        }
开发者ID:R4P3-NET,项目名称:AccountingServerEmulatorSource,代码行数:35,代码来源:Program.cs

示例13: StreamContent

        protected StreamContent(Byte[] contentBytes)
        {
            Debug.Assert(contentBytes != null);

            ContentBytes = contentBytes;
            ContentLength = (UInt32)contentBytes.Length;
        }
开发者ID:Blisse,项目名称:Windows8MASA,代码行数:7,代码来源:StreamContent.cs

示例14: District

 public District(DistrictTypes type, Byte id, LanguageCodes langCode = LanguageCodes.EN)
 {
     _type = type;
     _lang = langCode;
     Type = (Byte)((Byte)type + (Byte)langCode);
     Id = id;
 }
开发者ID:harleyknd1,项目名称:rAPB,代码行数:7,代码来源:District.cs

示例15: SendFile

        private static void SendFile()
        {
            // Создаем файловый поток и переводим его в байты
            Byte[] bytes = new Byte[fs.Length];
            fs.Read(bytes, 0, bytes.Length);

            Console.WriteLine("Отправка файла размером " + fs.Length + " байт");
            try
            {
                // Отправляем файл
                sender.Send(bytes, bytes.Length, endPoint);
            }
            catch (Exception eR)
            {
                Console.WriteLine(eR.ToString());
            }
            finally
            {
                // Закрываем соединение и очищаем поток
                fs.Close();
                sender.Close();
            }
            Console.WriteLine("Файл успешно отправлен.");
            Console.Read();
        }
开发者ID:Pashahasband,项目名称:SpaceKurs,代码行数:25,代码来源:Program.cs


注:本文中的System.Byte类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。