You would do this if you needed to perform some form of cleanup that is only required if an error occures but don't want to swallow the exception at that point in the code. Catching and then immediately re-throwing without doing anything else serves no purpose though.
LobsterDK
Posts
-
Try {//code} catch{throw;} ? -
C# and old "C" DllsYes, as with the requirement of defining the function signature in C# you also have to supply a description of the structure as well. For the structure you provided the sig would be [StructLayout(LayoutKind.Sequential)] struct SerialInfoMD { [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)] public byte[] ID; public byte Something; public int New; // note the capitalization change. Syntax error otherwise. } Things can get tricky when marshalling data between managed and unmanaged code. For example, in your function signature you have the return type as ulong. Is the return type for the C function an unsigned long? Unsigned long is 32-bits on Win32 but is 64-bits on .NET so the appropriate return type in the C# method is uint if the return type on the C function is unsigned long. It gets even more murky when dealing with arrays. You might wanna check out information on data marshalling on MSDN. Try this URL for a start. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconInteropMarshaling.asp
-
A silly listview questionWhat you are trying to do is not directly possible with the listview provided with .NET. The items collection is a collection of data associated with each element in the list, not a collection of controls to be displayed within the list. By default, if no string is supplied when adding items to the collection the objects ToString method is used to get the string to display. This is why you are getting the output you are getting. There are articles here on Code Project that show listview implementations that are capable of docking other controls within the listview. Note that it's not something you will be able to do with a trivial amount of code (though not an unobtainable goal either).
-
using a switch for a range of numbersThis is one of those features that VB has that I wish C# supported. You can just add case statements for each of the values adding the break statement to the last case in the range switch (value) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: DoSomething (); break; } not pretty but it works.