Usually you don’t specify a type for an enumeration and the default will be considered, which is int.In the following example we change the type to unsigned int (uint):
When you have to pass an array to a method, you can directly pass the values without creating the array
If you have to pass an array to the method myMethod you would usually do something similar to this: int[] myArray = new int [3] {23, 48, 96, 114};myClass.myMethod(myArray); But why create an array when you can pass the integers directly? The compiler takes care to pack the integers into an array. myClass.myMethod(23, 48, 96, 114);
How to check if a registry key / subkey already exists
The following example shows you how to check if a key in the Windows registry exists, in this case the key named Test which is situated in HKEY_CURRENT_USER\Software\Geekpedia. Registry.CurrentUser tells the program to use HKEY_CURRENT_USER. We use double backslashes to escape the slash in the registry path, but we can aswell use:
Array creation must have array size or array initializer
Array creation must have array size or array initializer error is caused by a line similar to the following: And the problem with this line is that you create a new array but you don’t define a size. When you create an array you have to either define a size for the array, or declare […]
How to retrieve the state of Caps Lock, Num Lock and Scroll Lock keys
In order to know whether or not Caps Lock, Num Lock or Scroll Lock keys are on, we need to make use of the Win32 API through a call to an unmanaged function. Since we’ll make a call to an unmanaged function, the following using statement is in order: using System.Runtime.InteropServices;The following is the definition for the unmanaged […]
Understanding and Resolving ‘Exception Has Been Thrown by the Target of an Invocation’ in C#
If you’re a C# developer, chances are you might have come across this error message. It can be puzzling and sometimes frustrating. But don’t worry, we’re here to help you understand and solve it. In C#, exceptions are a way for the program to tell you that something unexpected happened. They are like warning signals. […]
How to check if a number is odd or even?
Advertisement More C# Resources The best way to see if a given number is odd or even is to use the modulus operator (%). The modulus operator returns the remainder when dividing two numbers. So if you do a modulus of 6 % 2 you get 0 because 6 divided by 2 doesn’t have a […]
Using the StatusBar control
How to create a StatusBar, use it for displaying text into it or use it with panels (StatusBarPanels).
Create shortcuts with a .NET application
This tutorial will show you the code you need to write to have your application create shortcuts to any path (the desktop, startup folder, etc.).
List display adapters using DirectX 9
This tutorial will show you how to retrieve information about your graphics display adapter, such as name, driver version, current resolution and refresh rate and supported resolutions and refresh rates. All this is done by using the DirectX 9 SDK.