|
Hi.
an example:
byte[] fileconte = new byte[6];<br />
(code and code....)<br />
ArrayList list = new ArrayList();<br />
list.Add(fileconte);
How i can use a foreach to get list objets into a byte[]?? like:
foreach (byte[] cont in list) {<br />
}
|
|
|
|
|
hi
byte[] byteArray = (byte[])list.ToArray(typeof(byte));
regards
|
|
|
|
|
this?
byte[] fileconte = new byte[6];
ArrayList list = new ArrayList();
list.Add(fileconte);
foreach (object cont in list) {
byte[] myByteArray = cont as byte[];
myByteArray[0] = 5;
}
Cheers
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hello,
CPallini wrote: byte[] myByteArray = cont as byte[];
As the 'as' could also return 'null',
CPallini wrote: myByteArray[0] = 5;
this could leed to an null ref exception!
All the best,
Martin
|
|
|
|
|
Of course I know, but I leave all the checking code as an exercise for the reader.
BTW that's enforce flexibility as you may choose to:
(1) Really write the checking code.
(2) Use a precondition/postcondition approach on your project.
(3) Simply thrust preceeding code (viable only for very small projects).
Cheers
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
, it's deep inside me to allways do an '!=null' check after 'as'.
All the best,
Martin
|
|
|
|
|
Because you got married to strategy no.1
It's a safe marriage: ALL THE BEST!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
All the best,
Martin
|
|
|
|
|
CHeck my last reply
Works Perfect
now... time to rest
|
|
|
|
|
I'm happy for you!
sleep well!
All the best,
Martin
|
|
|
|
|
Hello,
This will work if you only Add "byte[]"'s to your List.
byte[] actArray1 = new byte[5];
byte[] actArray2 = new byte[6];
ArrayList actList = new ArrayList();
actList.Add(actArray1);
actList.Add(actArray2);
foreach(byte[] actArray in actList)
{
int length = actArray.Length;
}
But will throw an exception (System.InvalidCastException') if you also add different types to the List:
byte[] actArray1 = new byte[5];
byte[] actArray2 = new byte[6];
Control actControl = new Control();
ArrayList actList = new ArrayList();
actList.Add(actArray1);
actList.Add(actArray2);
actList.Add(actControl);
foreach(byte[] actArray in actList)
{
int length = actArray.Length;
}
There for you could use:
byte[] actArray1 = new byte[5];
byte[] actArray2 = new byte[6];
Control actControl = new Control();
ArrayList actList = new ArrayList();
actList.Add(actArray1);
actList.Add(actArray2);
actList.Add(actControl);
foreach(object actObject in actList)
{
byte[] actArray = actObject as byte[];
if(actArray!=null)
{
int length = actArray.Length;
}
}
IF you are using framework > .Net1.1, you could use a generic list.
All the best,
Martin
|
|
|
|
|
Thanks
Now i'm remember that byte in ArrayList
This is my code:
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
Program a = new Program();<br />
<br />
byte[] actArray1 = new byte[5];<br />
byte[] actArray2 = new byte[5];<br />
byte[] cant = new byte[5];<br />
ArrayList actList = new ArrayList();<br />
<br />
actArray1[0] = 0x6f;<br />
actArray1[1] = 0x6f;<br />
actArray1[2] = 0x5f;<br />
actArray1[3] = 0x6f;<br />
actArray1[4] = 0x1f;<br />
<br />
actArray2[0] = 0x6a;<br />
actArray2[1] = 0x6f;<br />
actArray2[2] = 0x6f;<br />
actArray2[3] = 0x6a;<br />
actArray2[4] = 0x4f;<br />
<br />
cant[0] = 0x6a;<br />
cant[1] = 0x6f;<br />
cant[2] = 0x6f;<br />
cant[3] = 0x6a;<br />
cant[4] = 0x4f;<br />
<br />
actList.Add(actArray1);<br />
actList.Add(actArray2);<br />
<br />
foreach (byte[] actArray in actList)<br />
{<br />
if (a.AreEqual(actArray,cant))<br />
Console.WriteLine("same byte array");<br />
}<br />
<br />
Console.ReadLine();<br />
}<br />
private bool AreEqual(byte[] a, byte[] b)<br />
{<br />
if (a.Length != b.Length)<br />
return false;<br />
for (int i = 0; i < a.Length; i++)<br />
if (a[i] != b[i])<br />
return false;<br />
return true;<br />
}<br />
}
|
|
|
|
|
Hi all,
We are automating an excel sheet using c#.
We provided security to the excel sheet by using protect() method.
The problem is,
the excel sheet can be modified by other unauthenticated users of the system inspite of the protection we provided programatically.
We need to modify the excel sheet only programatically but not manually by opening the excel sheet and modify data in the cells.
We also tried setting the protection level attributes in the excel sheet tools
manually...But we are not satisfied as the protection level attributes can also be changed by others.
Please help us.
Regards,
IET
|
|
|
|
|
explain me secend FDemo , explain that what is it? it has the same name with class:
class FDemo {
int x;
FDemo (int i) {
x = i;
}
|
|
|
|
|
Hello,
It's a parameterised constructor;
The constructor name has to be equal with the class name!
A class can have more than one constructor:
class FDemo
{
int x;
FDemo()
{
}
FDemo(int i)
{
x = i;
}
}
If you now want to instanciate the class you could use:
FDemo fdemo = new FDemo();
or:
int actValue = 5;
FDemo fdemo = new FDemo(actValue);
All the best,
Martin
|
|
|
|
|
thanks. but why we use constructor?
|
|
|
|
|
ptvce wrote: but why we use constructor?
Like I said, to instanciate a class;
Or, do you mean, why we use parameterized constructors?
All the best,
Martin
|
|
|
|
|
I think you might want to buy a book on OOP, as this is a very fundamental question to understanding it.
Standards are great! Everybody should have one!
|
|
|
|
|
hi all
i am doing a chatting a softeware and my Qn is how can i blink the form when it receives a message ...i mean if the form is minimized, the form should blink on receiving a message..
Regards
Joemon Varghese
|
|
|
|
|
Hi,
i can't help you with a blinking form, but what do you think of a blinking notifyIcon? You would just need a timer to change the notifyIcon each second or so.
Regards
|
|
|
|
|
i need to know What is SSL Encryption means ? how to get ssl encryption in page?
sathimailin
|
|
|
|
|
sathimailin1 wrote: What is SSL Encryption means
SSL is Secure Socket Layer, an encryption mechanism used to send information securely on internet. Basically it holds a public key and a private key.
sathimailin1 wrote: how to get ssl encryption in page?
You have to install SSL on IIS. And browse your site through HTTPS protocol. If your web applications really needs to send sensitive information like Credit card numbers, you could use SSL. But it always requires more processing overhead and financial overhead.
|
|
|
|
|
Thanks a lot for ur reply and from where i ll get the SSL to install and how to install it on IIS. can u please make me clear.
sathimailin1
|
|
|
|
|
|
Really good one u linked me and thanks
i voted you 4
sathimailin1
|
|
|
|