Programming Tutorial On The Way

free online programming resource on dotnet, csharp, web related topics

Simplify Boolean Logic

Many times a Boolean equation quickly becomes large, complex, and even unmanageable. Simplifying your Boolean logic will benefit your code by making it less cluttered and making its logic clearer and more readily understood. This simplification will lessen the number of potential locations in your logic where bugs can hide and at the same time improve maintainability. When learning about logic in Mathematic subject, you will find many theorems about simplifing logic. The table below shows the list of theorems that can be applied. Assume that w, x, y, and z are all variables of type bool. The Theorem ID column in this table allows easy identification of which theorems are being used in the Boolean equations that are being minimized. Read the rest of this entry »

Popularity: 3% [?]

You need to build several classes that share many common traits. These classes may share common properties, methods, events, delegates, and even indexers; however, the implementation of these may be different for each class. These classes should not only share common code but also be polymorphic in nature. That is to say, code that uses an object of the base class should be able to use an object of any of these classes in the same manner.
Read the rest of this entry »

Popularity: 3% [?]

When creating a custom data type; structure or class; if it is stored in an array of ArrayList, you can use the Array.Sort and ArrayList.Sort methods to do a custom sorting of the data type in the array, you can also use it in a SortedList collection. This can be done by implementing the IComparable and/or IComparer interfaces.

By implementing the IComparable interface on your class (or structure), you can take advantage of the sorting routines of the Array, ArrayList, and SortedList classes. The algorithms for sorting are built into these classes; all you have to do is tell them how to sort through your classes via the code you implement in the IComparable.CompareTo method. The following class, Square, implements this interface: Read the rest of this entry »

Popularity: 4% [?]

When creating a custom data type; structure or class; if it is stored in an array of ArrayList, you can use the Array.BinarySearch and ArrayList.BinarySearch methods to do a custom searching of the data type in the array. This can be done by implementing the IComparable and/or IComparer interfaces.

By implementing the IComparable interface on your class (or structure), you can take advantage of the search routines of the Array, ArrayList, and SortedList classes. The algorithms for searching are built into these classes; all you have to do is tell them how to search through your classes via the code you implement in the IComparable.CompareTo method. The following class, Square, implements this interface:
Read the rest of this entry »

Popularity: 2% [?]

All structures come with a predefined Equals method that internally uses reflection. Take a look at the IL code for the Equals method of the System.ValueType class in the mscorlib.dll using Ildasm. You will notice that the implementation of this Equals method first checks to see whether the object passed in to this method is null. If it is not, the next check is to determine whether the object implementing the Equals method is the same type as the one passed in to it. If so, a check is made using the internally implemented method ValueType.CanCompareBits. If this method determines that the bits of the two objects can be compared successfully, a call is made to ValueType.FastEqualsCheck. If this faster check for equivalence cannot be made, reflection which performs sloweris used to obtain all the instance fields of both objects and compare them individually within a loop. This may not be the best way to go for your custom ValueType?afrom both a performance and a logic point of view. Read the rest of this entry »

Popularity: 2% [?]

Different languages sometimes handle specific conversions differently; you need a way to perform these conversions in a consistent manner across all .NET languages. The conversion can be between any two of the following types: bool, char, sbyte, byte, short, ushort, int, uint, long, ulong, float, double, decimal, DateTime, and string. Read the rest of this entry »

Popularity: 4% [?]

The .NET Framework Class Library like Int32, String classes provide the built-in Parse method to do conversion of a string value to the actual class. You need a way of accepting a string containing a textual representation of an object and converting it to an object usable by your application. For example, if you were provided with the string representation of a line (x1, y1)(x2, y2), you would want to convert it into a Line structure.

Read the rest of this entry »

Popularity: 3% [?]

Your class or structure needs to control how its information is displayed when its ToString method is called. For example, when creating a new data type, such as a Line class, you might want to allow objects of this type to be able to display themselves in a textual format. In the case of a Line object, it would display itself as “(x1, y1)(x2, y2)“.
You can override and/or implement the IFormattable.ToString method to display numeric information, such as for a Line structure: Read the rest of this entry »

Popularity: 4% [?]

« Previous Entries