Search This Blog

Friday, February 5, 2016

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.









Clear filters RadGrid Telerik

Telerik > RadGrid > Clear filter

foreach (var column in RadGrid1.MasterTableView.Columns)
{
         column.CurrentFilterFunction = GridKnownFunction.NoFilter;
         column.CurrentFilterValue = string.Empty;
}

RadGrid1.MasterTableView.FilterExpression = string.Empty;
RadGrid1.MasterTableView.Rebind();





Monday, December 21, 2015

Print directly RadGridView

Telerik > Windows Forms > RadGridView > Print directly 


radGridView1.Print();







Thursday, December 10, 2015

Clear contents of a file c#

C# > Clear contents of a file

WriteAllText creates a new file, write the contents to the file, and then closes the file. If the target file already exists, it is overwritten.

Example

 System.IO.File.WriteAllText(filename, string.Empty);