How can I delete an item from an array in VB.NET?

As Heinzi said, an array has a fixed size. In order to ‘remove an item’ or ‘resize’ it, you’ll have to create a new array with the desired size and copy the items you need as appropriate. Here’s code to remove an item from an array: <System.Runtime.CompilerServices.Extension()> _ Function RemoveAt(Of T)(ByVal arr As T(), ByVal … Read more

Arithmetic operation resulted in an overflow. (Adding integers)

The maximum value of an integer (which is signed) is 2147483647. If that value overflows, an exception is thrown to prevent unexpected behavior of your program. If that exception wouldn’t be thrown, you’d have a value of -2145629296 for your Volume, which is most probably not wanted. Solution: Use an Int64 for your volume. With … Read more

Setting CLS compliance for a .NET assembly

Visual Studio adds a directive for the compiler, and the compiler checks the code for some more strict rules than in the native programming language. You can add the CLS compliant attribute to all your project by adding the assembly level attribute [assembly: CLSCompliant(true)] anywhere in your project, generally in the assemblyinfo.cs file. If the … Read more

List of exceptions that CAN’T be caught in .NET

The only exception that cannot be caught directly is (a framework thrown) StackOverflowException. This makes sense, logically, as you don’t have the space in the stack to handle the exception at that point. From the docs: Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the … Read more

Capture screenshot Including Semitransparent windows in .NET

Forms that have the TransparencyKey or Opacity property set are so-called layered windows. They are shown using the “overlay” feature of the video adapter. Which make them being able to have their transparency effects. Capturing them requires turning on the CopyPixelOperation.CaptureBlt option in the CopyFromScreen overload that accepts the CopyPixelOperation argument. Unfortunately, this overload has … Read more

ConcurrentBag Vs List

Internally, the ConcurrentBag is implemented using several different Lists, one for each writing thread. What that statement you quoted means is that, when reading from the bag, it will prioritize the list created for that thread. Meaning, it will first check the list for that thread before risking contention on another thread’s list. This way … Read more

VB.NET Function Return

The difference is that they DO DIFFERENT THINGS! ‘Return value’ does 2 things: 1. It sets the function return value at that point 2. It immediately exits the function No further code in the function executes! ‘Functionname = value’ does 1 thing: 1. It sets the function return value at that point Other code in … Read more