Search This Blog

Friday, February 5, 2016

How To Convert A Number To an ASCII Character C#

C#  > System > Convert > ToChar

Converts the value of the specified 8-bit unsigned integer to its equivalent Unicode character.

Example

Convert a number to an ASCII Character

 var asciiCode = System.Convert.ToChar(65).ToString(); // 'A'





Convert Class C#

C#  > System > Convert Class

This class is used for conversion to and from the base data types in the .NET Framework.

Methods






Thursday, January 21, 2016

Get all IP Addresses from devices attached to the machine C#

C# > System.Net > Dns > IPHostEntry > AddressList

AddressList gets or sets a list of IP addresses that are associated with a host.

Example

Get all IP Addresses from devices attached to the machine 


string hostName = Dns.GetHostName();
IPHostEntry ipHostEntry = Dns.GetHostEntry(hostName);
foreach (IPAddress item in ipHostEntry.AddressList)
{
var IPAddress = item.ToString();
}






Tuesday, January 5, 2016

C# Unit test to check if the class implements an interface with IsInstanceOfType method

C# > Assert Class > IsInstanceOfType

This method verifies that the specified object is an instance of the specified type. 

Example

Test class implements a specific interface.

var result = typeof(MyClass).GetInterfaces()[0];

// Assert

Assert.IsInstanceOfType(typeof(IMyClass), result.GetType());