how to initialize a byte array
-
14 Ağustos 2012 Salı 03:51I found some people initialize byte array like this: byte[] = new byte[0x1000]; why initialize its length by hexadecimals rather than by decimal?
Tüm Yanıtlar
-
14 Ağustos 2012 Salı 05:53
Citing a similar thread, maybe 0x1000 “was implicitly known as a hex value”, so you let the compiler to convert it to 4096, or “the author of the code felt that 0x1000 would be more readable than 4096 - possibly for no better reason than the fact that humans kinda like round numbers” [http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/78506c5e-0e8d-43e1-8fa0-6a9fd2c07a3e].
- Düzenleyen Viorel_MVP 14 Ağustos 2012 Salı 05:55
- Yanıt Olarak İşaretleyen Doraemon_3 14 Ağustos 2012 Salı 06:09
-
14 Ağustos 2012 Salı 12:12
You can simply go for decimal too..the reason the author goes for 0x1000 is to enhance code readability...it looks better..that's it!
like this:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { sbyte[] s_byte = new sbyte[10]; /*normal decimal sized array*/ } } }happy coding..!
- Yanıt Olarak İşaretleyen Jason Dot WangMicrosoft Contingent Staff, Moderator 21 Ağustos 2012 Salı 07:57