Expand|Select|Wrap|Line Numbers
- namespace consolepractice
- {
- class Program
- {
- static byte[] asyncreadbytes;
- static byte[] asyncwritebytes;
- static FileStream fileS;
- static FileInfo file;
- static void Main(string[] args)
- {
- file = new FileInfo(@"c:\akshay.pallu");
- fileS = file.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);
- AsyncCallback readcallback = new AsyncCallback(readfunc);
- AsyncCallback writecallback = new AsyncCallback(writefunc);
- asyncwritebytes = System.Text.Encoding.Unicode.GetBytes("luck");
- foreach (byte b in asyncwritebytes)
- Console.Write((char)b);
- Console.WriteLine("\nBegin writing....");
- Console.WriteLine("No of bytes=" + asyncwritebytes.Length);
- fileS.Position = 0;
- fileS.BeginWrite(asyncwritebytes, 0, 8, writecallback, asyncwritebytes);
- asyncreadbytes = new byte[8];
- Console.WriteLine("Begin reading....");
- fileS.Position = 0;
- fileS.BeginRead(asyncreadbytes, 0, 8, readcallback, asyncreadbytes);
- Console.ReadKey();
- }
- static void writefunc(IAsyncResult result)
- {
- Console.WriteLine("written.");
- fileS.EndWrite(result);
- }
- static void readfunc(IAsyncResult result)
- {
- Console.Write("Read this--->");
- foreach (byte b in (byte[])result.AsyncState)
- Console.Write((char)b);
- fileS.EndRead(result);
- }
- }
- }
I need to know why the output is l u c k and not luck.
What i can figure out is this:
the character 'l' gets stored as unicode (16 bits).
The low order byte store the char l (binary calue 108) as [01101100] and the high order byte stores all zeroes[00000000] so the char is stored as
[00000000] [01101100].
All the other characters are stored in the same way (the most siignificant byte being made up of all zeroes).
All the tiem of reading we read byte wise.
so the[00000000] byte is read first which when casted to unicode char(char) tp produce the equivalent character.But sadly this does not happen as it is printed as l<space>u<space>
not as <space>l<space>u
WHY IS IT SO