How to get local host name in C# on a Windows 10 universal app -
string machinename = system.environment.machinename; this code doesn't work me, error code 'environment' not contain definition 'machinename'
i'm using visual studio 2015 , universal app c#
please list namespace need use when post answer.
you need use networkinformation.gethostnames.
var hostnames = windows.networking.connectivity.networkinformation.gethostnames(); but note method return multiple hostnames.
in case, returns 4 hostnames of displaynames mycomputername, mycomputername.local plus 2 ip addresses.
so guess it's safe -
using windows.networking; using windows.networking.connectivity; var hostnames = networkinformation.gethostnames(); var hostname = hostnames.firstordefault(name => name.type == hostnametype.domainname)?.displayname ?? "???";
Comments
Post a Comment