본문 바로가기

c#11

C# 제네릭 메서드 제너릭 메서드에 대해서 소개합니다. 제너릭 이란? 저장하거나 사용하는 하나 이상의 형식에 대한 자리 표시자(형식 매개 변수)를 포함하는 클래스, 구조체, 인터페이스 및 메서드라고 정의되어 있는데, 쉽게 말하자면, 한 가지 기능(클래스, 구조체, 인터페이스, 메소드)에 여러 형식(문자열, 숫자, 객체 등등)을 받고 싶다! 라고 생각하시면 됩니다. 예를 들어 Dictionary에 문자열 타입과 숫자타입이 공존한다고 치면, 아래와 같은 메서드를 사용할 수 있습니다. public static T GetValue(Dictionary dictionary, string key, T defaultValue = default(T)) { try { if (dictionary.ContainsKey(key)) { object.. 2023. 7. 21.
C# Url Combine 이 코드는 Url을 Combine 시 / 가 중복되지 않도록 하지않는 코드입니다. public static string Combine(string uri1, string uri2) { uri1 = uri1.TrimEnd('/'); uri2 = uri2.TrimStart('/'); return string.Format("{0}/{1}", uri1, uri2); } 2022. 6. 10.
C# parse xml pretty string XML 을 파싱하고, 보기 좋게 세팅하는 코드입니다. public static string PrintXML(string inputXml) { XmlDocument document = new XmlDocument(); document.Load(new StringReader(inputXml)); StringBuilder builder = new StringBuilder(); using (XmlTextWriter writer = new XmlTextWriter(new StringWriter(builder))) { writer.Formatting = Formatting.Indented; document.Save(writer); } return builder.ToString(); } 2022. 1. 20.
Javascript C# String.Format 메서드와 동일한 기능 // C# String.Format 메서드와 동일하게 동작시키기 위한 함수 String.format = function () { // The string containing the format items (e.g. "{0}") // will and always has to be the first argument. var theString = arguments[0]; // start with the second argument (i = 1) for (var i = 1; i 2022. 1. 18.
반응형