Search This Blog

Friday, February 26, 2016

XmlNamespaceManager class c#

C# > XML > XmlNamespaceManager

XML namespaces associate element and attribute names in an XML document with custom and predefined URIs.

Methods












Tuesday, February 23, 2016

Convert ushort to byte array and to ASCII code C# using BitConverter

C#  > System > BitConverter

Converts 

  • base data types to an array of bytes,
  • array of bytes to base data types.


Example

Convert ushort to ASCII code.
(ascii code 2 bytes array)


ushort number = 5678;

byte[] byteArray = BitConverter.GetBytes(number);

foreach (var result in byteArray)
{
string val = System.Convert.ToChar(result).ToString();
}





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());







Tuesday, December 22, 2015

What is ADO.NET

ADO.NET provides a set of components for creating distributed, data-sharing applications.

ADO.NET provides consistent access to data sources such as SQL Server and XML, and to data sources exposed through OLE DB and ODBC. Data-sharing consumer applications can use ADO.NET to connect to these data sources and retrieve, handle, and update the data that they contain.