본문 바로가기

c#11

C# string to int 확장형 namespace System { public static class StringConvert { public static int ToConvertInt(this string self, int defalut = 0) { int value = defalut; int.TryParse(self, out value); return value; } } } 2022. 1. 11.
C# byte to int static void Main(string[] args) { { // Bytes to int byte[] bytes = { 0, 0, 25, 25 }; // 이 컴퓨터 아키텍처에서 데이터가 저장되는 바이트 순서("endian")를 나타냅니다. // 이 아키텍처가 little-endian이면 true이고, big endian이면 false입니다. if (BitConverter.IsLittleEndian) Array.Reverse(bytes); int i = BitConverter.ToInt32(bytes, 0); Console.WriteLine("int: {0}", i); // Output: int: 6425 } { // int to bytes byte[] bytes = BitConverter.GetByt.. 2022. 1. 11.
C# 클라이언트 Browser 정보얻기 public static string GetClientBrowser() { try { HttpContext chc = System.Web.HttpContext.Current; if (chc == null) return string.Empty; return chc.Request.Browser.Capabilities[""] != null ? chc.Request.Browser.Capabilities[""].ToString() : chc.Request.Browser.Browser + chc.Request.Browser.Version; } catch { } return String.Empty; } 2022. 1. 7.
C# 로컬IP(서버IP)정보 조회 public static string GetLocalIP() { try { IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName()); foreach(IPAddress ip in host.AddressList) { if(ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { return ip.ToString(); } } return string.Empty; } catch(Exception ex) { Console.WriteLine(ex.ToString()); } return string.Empty; } 2022. 1. 6.
반응형