c# check internet connection easy

C#
System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()
Source

Also in C#: