Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)

Operator Overloading in C#

Fig 2. C# Class With Overloading + Operator

We can overload an operator using the operator keyword followed by the symbol for the operator. In this example, we will overload an + operator to append comma with the strings. Since + is a binary operator, we need two instances of the string. In this example, we will write a class called CommaStr and have a static method with name ‘+’ which acts as an overloaded operator function. Unlike C++, Operator Overloading can be done for very specific operators in C#. You can refer MSDN for list of operators that can support overloading.

Continue Reading →

JavaFx LinearGradient Examples

Fig 3. Changing the Gradient Axis in JavaFx Gradient Fill

The LinearGradient class helps in applying such a gradient to any JavaFx shapes. In JavaFx, Linear Colour Gradient is applied by an axis in which a colour changes gradually from one point to another point. We call this axis as Gradient Axis. If we draw a line perpendicular to a specific point in the linear gradient axis, all the pixels in the perpendicular axis represents same colour.

Continue Reading →

Dynamic ExpandoObject in C#

Fig 1. Create Expando Object

In the previous article, we learned about Anonymous Type to define properties at runtime. But these properties are read only and the type will not allow changing it after creation. C# provides a class called DynamicExpando which will also allow adding the properties at runtime. But we can read and write the property values at runtime with this object. Since the type allow adding the members on the fly, the compiler will not perform any type checking. We can also…

Continue Reading →

JavaFx Pattern Fill Shapes

Fig 7 - Setting the proportional to false

JavaFx allows filling the closed shapes with a color. It is also possible to create an image and use it to fill the closed shapes. JavaFx provides the ImagePattern class which defines how the image pattern paints the target 2d shape. The ImagePattern class needs an Image object and fill rectangle (also called as Anchor Rectangle) definition. In this example, we will explore the ImagePattern class and fill the shapes rectangle and circle.

Continue Reading →