localIP, publicIP 가져오기 ▶ 서버를 개발하다보면 localhost나 127.0.0.1 외에 IP 주소가 필요한 경우가 있다. ▶ 그때 매번 cmd창 켜서 ipconfig 검색하고, "내 아이피검색" 안해도 아래 코드를 사용하면 편하게 PC의 IP를 가져 올 수 있다. LocalIP 가져오기 public static string GetLocalIP() { string result = string.Empty; var host = Dns.GetHostEntry(Dns.GetHostName()); foreach (var ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { result = ip.ToStrin..
파일 압축하기 코드 class Program { static void Main(string[] args) { Console.WriteLine("== Hello World =="); try { // 1. 압축할 폴더 생성 var directoryName = @"D:\ZipTest\" + "NewZip"; System.IO.Directory.CreateDirectory(directoryName); // 복사할 파일 이름 var fileList = new List { "testfile1.txt", "testfile2.txt" }; foreach (var fileName in fileList) { // 원본 파일 위치 var sourceFile = System.IO.Path.Combine(@"D:\ZipTest..
string GetMD5Hash(string password) { var mdHash = MD5.Create(); var data = mdHash.ComputeHash(Encoding.UTF8.GetBytes(password)); var stringBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { stringBuilder.Append(data[i].ToString("x2")); } return stringBuilder.ToString(); }
Dapper를 사용할 때 insert시 pk를 자동으로 채워주려면 해당 변수를 [Key] 로 해줘야함 ex) public class ItemEntity { [Key] public long ItemIdx {get;set;} public long InsertToDB() { conn.Insert(this); return ItemIdx; } } - explicitKey키로 어트리뷰트를 하면 위의 방법은 적용되지 않음 [추가 + ] [key] : "데이터베이스에서 자동으로 생성되는 키로 속성 지정"으로 정의 ( Auto Increment) [Explicti Key] : 키는 키인데 자동 증가 하지 않는 컬럼 https://stackoverflow.com/questions/49428967/dappers-explic..
- 본인 pc localIP 받는 코드. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 string GetLocalIP() { string result = string.Empty; var host = Dns.GetHostEntry(Dns.GetHostName()); foreach (var ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { result = ip.ToString(); break; } } return result; } er
Main 함수 using System; using System.Collections.Generic; namespace Study { class Program { static void Main(string[] args) { // IAnimal 리스트 var list = new List(); // type.GetType 으로 Cat 객체 생성 var animal = Type.GetType("Study.Cat"); var cat = Activator.CreateInstance(animal) as Cat; cat.Name = "고양이"; list.Add(cat); // type.GetType 으로 Dog 객체 생성 animal = Type.GetType("Study.Dog"); var dog = Activato..