As @AvkashChauhan pointed out, you should be able to retrieve a hostname through the Dns class. I'm curious, though, why you need the hostname. If it's for communication between role instances, you actually don't need the hostname. Rather, you can query the role instance endpoints (assuming you set one up as an internal endpoint), and then for each instance, you can request the ip address and port, which would allow you to establish a direct connection to any given instance. So, modifying the code you had:
foreach (RoleInstance instance in RoleEnvironment.Roles["MyRole"].Instances) {
writeline(InstanceEndpoints["myendpoint"].IPEndpoint);
You may, indeed, need hostname for something, and if so, just ignore this answer. But... if what you're looking for is a way to make tcp/http/udp connections between role instances, this is a pretty simple way to retrieve all the ip/port combinations for your role instances.