>Q1:
>
>if (...)
>{
> byte[] var1 = new byte[4];
> var1[0] = 'A';
> var1[1] = "B';
> var1[2] = 'C';
> var1[3] = 'D';
> CheckInput(var1); // CheckInput(bytes[] bytes)
Don't you want a char[] instead?
>When defining a variable like "var1" in the above code to hold a string of
>"ABCD", should it be declared as:
>
>byte[] var1 = new byte[5];
>
>with the last byte to be assigned to '\0' like in C, since var1 will be put
>in "CheckInput(bytes[] bytes)" call?
There's no need to zero terminate an array. All arrays keep track of
their length anyway.
>Q2:
>
>if (...)
>{
> byte[] var1 = new byte[4];
> var1[0] = 'A';
> var1[1] = "B';
> var1[2] = 'C';
> var1[3] = 'D';
> CheckInput(var1);
> ...
>}
>
>if (...)
>{
> byte[] var1 = new byte[10];
> ...
>}
>
>Will it be Okay to reuse the var1 this way? Or is there a better to release
>var1 for reusing it in the following code?
Not sure exactly what you're asking here, and what you mean by
"release". You're not reusing the same variable, only the name. var1
in the fist block is different from var1 in the second. Of course it
might be better for other people reading your code if you get a little
more creative in naming your variables, but to the compiler it doesn't
matter.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com
Please reply only to the newsgroup.