What is Upcasting and Downcasting in C# ?

Upcasting is basically an object creation mechanism by which we create objects by referring to their base class. We do this by replacing the sub-class name by the base-class name in the object definition. This particularly comes in handy when you know that a specialized object created will not necessarily use all the functions of a specialized sub-class has got to offer. So, replace a sub-class(inherited class) by a base-class and all you have done is Upcasting.


Read a Value from the Windows Registry in C# 5.0

In the previous post we saw how to create a registry i.e. write a value into the Windows registry. Now we shall retrieve back the exact value that we had written before. To do this we need to retrieve the value in a String variable.

We shall take the value by its exact location & the name of the property. Note that the property resides in a folder and the value we read is the Data of that property. Have a look at the present snapshot of the system:

  • Root Folder is HKEY_CURRENT_USER
  • Parent Folder is CSharp_Website
  • Property/Attribute/Key Name is Really
  • Property/Attribute/Key Value is Yes!

How to Write into Windows Registry in C# 5.0

Developing a real application almost everytime requires the storing of some important values in the Windows Registry. The Windows Registry gives the power to store variables of different types by any application and use them as and when required. You can also store values in the form of texts, external files or saved documents then why use the Registry? Because the Registry allows above all the values to be stored and read in a standardized way which can be read by compatible applications as and when required. Also, the deletion of corresponding files does not alter the information in the Windows Registry. The contents have to be modified explicitly to delete or modify existing values.

The windows registry can be modified using the C# programming interface. In this section we shall see how to write to a known location in the windows registry. The Windows registry consists of different locations in an explorer style and looks as shown below:

Create Form TextBox Controls at Runtime

Sometimes you might want to create a user control at run-time.  These are times when you are not sure of what controls to include during the form designing phase of your program.  What we usually do is to draw all available controls in the designer form. Then at run-time we simply make the controls invisible leaving us with workable visible controls. But there is a better method. What should be done is exactly illustrated below. You should write code to draw the controls at run-time. You should draw the controls when needed to save memory.