|
Convert Hexadecimal To Number In C#
To convert a Hexadecimal to a number we can use an overload of Convert.ToInt32 method.
Using the overload I can convert for example hex string “BB” to a number.
int number = Convert.ToInt32("BB", 16);
And the number variable gets assigned value of 187.
Get Name Of Current Executing Assembly In C#
This is where reflection comes in handy. The following code snippet shows you how to get the name of executing assembly.
string assemblyName;
assemblyName = System.Reflection.Assembly.GetExecutingAssembly().FullName;
Console.WriteLine(assemblyName);
Output for the above code returns the fully qualified name as shown below
To just get the Assembly name we can use this snippet.
string assemblyName;
assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
Console.WriteLine(assemblyName);
Here is the output.
Get CD Or DVD Drive Information Using WMI And C#
This snippet shows you how to get information about all CD / DVD drives on your machine using WMI and C#. To run the code you need to add reference to System.Management.
ManagementObjectSearcher mgmtObjects =
new ManagementObjectSearcher("Select * from Win32_CDROMDrive");
foreach (var item in mgmtObjects.Get())
{
Console.WriteLine("Drive Letter - \t" + item["Drive"]);
Console.WriteLine("Name - [...]
Programmatically Take Screenshot Using C#
To do this you will need to add references to System.Drawing and System.Windows.Forms. Make sure that you have following using statements:
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
In your method add this code. It will take a screenshot of your primary screen and save it to a file.
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
[...]
Get A List Of Running Processes Using C# - Code Snippet
This code will retrieve a list of currently running process on a machine and write their names to console.
// Get A List of process using
// System.Diagnostics.Process class
List<Process> processes = Process.GetProcesses().ToList();
// Write them out to Console
processes.ForEach(x => Console.WriteLine(x.ProcessName));
var Keyword In C#
I have a confession to make. When I saw var keyword for the first time I did not like it at all. My first opinion was that var was so variant like. Call me a control freak but I like to clearly see what I am declaring. And var was something I thought made the [...]
Code Sample: Programmatically Download File Using C#
While browsing forums today I came across a question which asked for a solution to download a file from a web server programmatically. The solution is very simple and below is the code which achieves the goal. Here I am downloading a file asynchronously on Button Click.
1: private void buttonDownloadFile_Click(object sender, EventArgs [...]
Fundamentals: Deep Cloning In C#
To make an object cloneable in .NET we should implement ICloneable interface. ICloneable is a simple interface with only one method Clone(). In this post I will show you how to make a deep clone of an object.
class Program
{
static void Main(string[] args)
{
[...]
Get A List Of Installed Applications Using LINQ And C#
To get a list of installed applications we need to look into registry. Microsoft.Win32 namespace contains objects which can be used to work with Windows Registry. In this post I will show you some code where I use the power of LINQ to retrieve and display a list of all applications installed on a machine.
The [...]
Programmatically Retrieve Information About Windows Services Using ServiceController
ServiceControl can be used to get information about a Windows Service on a machine. In this post I will show you how to retrieve information about a service using ServiceControl.
To begin with lets examine the properties for ServiceControl. Through the designer we can set the ServiceName property. This can be set to the name of [...]
Tutorial Reading A Text File Using LINQ
Introduction
At times us developers have to deal with delimited text files in our applications. Such files have been around since yonks and I often come across data import/export tasks where delimited files are used. Till now the common way in .NET has been to read each line and then extract data using some sort of [...]
Write To Vista Event Log Using C#
Event Log is a central place to log application events. These events can be errors, warnings or just information. Each event log entry in Windows Vista has a level of event, date and time the event occurred, source of event, an event Id and a task category. While event logs such as Application, System, Security [...]
Popular Post
Tag Cloud
Code Snippets
- Get Current Windows User In C#
- Get Width And Height Of Image In C#
- Get Windows Registry Size With WMI And C#
- Reverse Array Elements Using C#
- Convert Hexadecimal To Number In C#
- Get Free Disk Space Using T-SQL
- SQL Server 2008 – Get All Indexes In A Database
- Get Name Of Current Executing Assembly In C#
- Get CD Or DVD Drive Information Using WMI And C#
- Get Last Row From Table Using LINQ To SQL

