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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -