02-07-2012 Normally, a programming language stops evaluating a composite condition when it finds one of following scenarios. (Condition 1) AND (Condition 2) Since the above composite condition to evaluate to true, both condition 1 and condition 2 have to evaluate to TRUE. If the condition 1 evaluates to FALSE then it is obvious that theContinue reading “Using Short-Circuit Condition Evaluation in VB using AndAlso and OrElse”
Category Archives: C#.Net
How To Exit or End a C Sharp (C#) Application
12-06-2012 To exit a c# program simply use following command: Environment.Exit(int Status); Status is the integer you return to tell the environment how your program concludes. If it executed according as expected or if it encountered any errors. The commonly used success value is zero 0 This will mean that your program termintaes without anyContinue reading “How To Exit or End a C Sharp (C#) Application”
How to Suggest Values or Autocomplete Values When A User Types Into a Combo Box
08-06-2012 .Net has a 5 seconds super easy way to achieve this. Use ComboBox.AutoCompleteSource and ComboBox.AutoCompleteMode properties: (Available from .Net 2.0 onwards) Steps: Load all possible values to ComboBox.Items collection – this is the easiest source available. Select Properties of the ComboBox and select ComboBox1.AutoCompleteSource to “List Items” Select ComboBox.AutoCompleteMode to anything other than “none”Continue reading “How to Suggest Values or Autocomplete Values When A User Types Into a Combo Box”
List.Find Method in C#.NET
30-05-2012 The List.Find method requires a delegate function which can compare an object of the same type of the list and return if the object matches the target object. You can either declare a delegate separately or use following easy shortcut. Following example populates a list of people and then finds for a particular entryContinue reading “List.Find Method in C#.NET”
Comparing Objects in .Net – Reference Equality
30-05-2012 Comparing two objects returns true if they point to the same entry of the heap. Menol ILT
How to Implement a Background Worker Thread that Supports Cancellation (How to Stop A Background Thread)
30-05-2012 The background worker in .net provides a method CancelAsync() to cancel a background worker. However, calling this method will not stop a worker thread there has to be several things you have to implement before. 1. First of all, for a BackgroundWorker to respond to a CancelAsync, you must set the WorkerSupportsCancellation flag. 2.Continue reading “How to Implement a Background Worker Thread that Supports Cancellation (How to Stop A Background Thread)”
Cannot Find Contents Of System.Configurations?
29-05-2012 The visual studio shows the System.Configurations namespace by default. But it doesn’t show that namespace content (such as System.Configuration.Configuration class) by default. You have to add a new reference to System.Configurations namespace explicitly. This is more confusing as it allows you to add using System.Configuration; in the class but then doesn’t show the contentsContinue reading “Cannot Find Contents Of System.Configurations?”
How to Convert a Stack to an Array Without Losing The LIFO Order
29-05-2012 The index of elements in a stack increments. i.e. the latest item would have the largest index (which is equal to Stack.Length – 1). But when you use Stack.ToArray() method it returns items in the other way. So the first item in the array is the last item you put in the stack. ThisContinue reading “How to Convert a Stack to an Array Without Losing The LIFO Order”
How To Use OpenFileDialog In WPF
WPF has it’s own encapsulated version of OpenFileDialog. You can find this under Microsoft.Win32 namespace. Sample code:
Use of “as” keyword as for casting in C#
2009-01-06 The keyword as doesn’t throw an exception if it fails to complete the casting operation. Instead it will return null. Other casting operations will throw an exception when the provided value cannot be casted. Since the “as” keyword sets or returns “null” value when it fails, the variable you use must be of aContinue reading “Use of “as” keyword as for casting in C#”