check if network is available c#

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

Also in C#: