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.
.Net C# 5 Codes on various topics & Visual Studio 2012 Source Codes available to direct download.
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:
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.
Check for Anagrams in .Net C# 5.0
This program shows how you can check if two given input strings are
Anagrams or not in CSharp language. Anagrams are two different words or combinations of characters which have the same
alphabets and their counts. Therefore a particular set of alphabets can
create many permutations of Anagrams. In other words, if we have the
same set of characters in two words(strings) then they are Anagrams.
We
create a function that has input as a character array pair of inputs. When we get the two different sets of characters, we check the count of each alphabet in these two sets. Finally, we tally and check if the value of character count for each alphabet is the same or not in these sets. If all characters occur at the same rate in both the sets of characters, then we declare the sets to be Anagrams otherwise not.
See the code below for C#:
Using Indexers in C#
Indexers are elements in a C# program that allow a Class to behave as an Array.
You would be able to use the entire class as an array. In this array you can store any type of variables. The variables are stored at a separate location but addressed by the class name itself. Creating
indexers for Integers, Strings, Boolean etc. would be a feasible idea.
These indexers would effectively act on objects of the class.
Lets
suppose you have created a class indexer that stores the roll number of
a student in a class. Further, lets suppose that you have created an object of
this class named obj1. When you say obj1[0], you are referring to the
first student on roll. Likewise obj1[1] refers to the 2nd student on
roll.
Build a Typing Master Game in C#
This is a basic typing game concept. The form will display random letters. If the player types one of them, it disappears and the accuracy rate goes up. If the player types an incorrect letter, the accuracy rate goes down. As the player keeps typing letters, the game goes faster and faster, getting more difficult with each correct letter. If the form fills up with letters, the game is over!
Caller Information in C# 5
Caller Information is a new concept introduced in C# 5. It is
aimed at providing useful information about where a function was called. It
gives information such as:
- Full path of the source file that contains the
caller. This is the file path at compile time.
- Line number in the source file at which the
method is called.
- Method or property name of the caller.
Subscribe to:
Posts (Atom)







