Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Download File from Internet Synchronously and Asynchronously



This program will let you download a file both ways i.e. Synchronously and Asynchronously. Just feed the file URL into the first text-box and the save file location into the second text-box  Then simply choose from the two options to download the file from the internet. 

Measure Difference between 2 Dates


Getting differences between two given dates is as easy as it can get. The function used here is the End_Date.Subtract(Start_Date). This gives us a time span that has the time interval between the two dates. The time span can return values in the form of days, years, etc.

Show and Invert RGB Colors in C#


This post will demonstrate how to show and convert colors when the Red Green & Blue values of those colors are given. We simple use a function and supply the Red, Green and Blue components in the parameter list. We shall also see how to Invert a color. In the image below the text color is set by the user. The background color is automatically set which is the Invert of the Text color. See image below to have a look at the final output of our WinForms application:



Named Arguments in .Net C#


Named Arguments are an alternative way for specifying parameter values in function calls. They work so that the position of the parameters would not pose problems. Therefore it reduces the headache of remembering the positions of all parameters for a function. It also helps to avoid the excess overloading of functions that contain less or more of the same set of parameters. 

They work in a very simple way. When we call a function, we would write the name of the parameter before specifying a value for the parameter. In this way, the position of the argument will not matter as the compiler would tally the name of the parameter against the parameter value. This makes it unnecessary to remember the organisation of the parameters in the function definition. 


Optional Parameters in .Net

Optional Arguments were introduced in C# 4.0 and this article will show you how to use them. Optional Arguments are necessary when you specify functions that have a large number of arguments. It can cut down time by making you pass on argument values to the most needy parameters in a situation. 

Optional Arguments are what their name suggests i.e. even if you do not specify them, its perfectly OK. But it doesn't mean that they have not taken a value. In fact we specify some default values that the Optional Parameters take when values are not supplied in the function call. In this way we gain the functionality of easily setting values once and using these values several times as a default unless something different is needed. 

Display all Files and Folders in a Directory in C#


You can easily list and display all the files and folders in a C# application using the DirectoryInfo class. First have a look at the application screenshot which uses this class to display the Files and Folders in a specified directory. All the Files and Folders are displayed in a ListView



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: