본문 바로가기

Common /C#5

String.Split에서 \r\n 처리 방법 String.Split에서 Enter Key(\r\n)은 다음과 같이 처리하면 된다. 1. string[] lines = doc.Split('\n'); for (int i = 0; i < lines.Length; i+= 1) lines[i] = lines[i].Trim(); 2. *예제.txt에는 \r\n이 포함된 문자열이 있다고 가정 string path = "예제.txt"; string content = File.ReadAllText(path); string[] lines = content.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); 2014. 5. 30.
Enumerable Class 1 : Enumerable Method - Aggregate Enumerable.Aggregate 메서드 네임스페이스: System.Linq 어셈블리: System.Core(System.Core.dll) 1. public static TSource Aggregate(this IEnumerable source,Func func )예제) string sentence = "천리길도 한 걸음 부터"; // 빈공백으로 각 단어를 words 배열에 담는다. string[] words = sentence.Split(' '); // 단어순서를 바꾸기 위해 새로운 문장의 시작부분에 각 단어를 추가 string reversed = words.Aggregate((workingSentence, next) => next + " " + workingSentence); Console.Wri.. 2014. 5. 22.
Enumerable Class 0 IEnumerable 을 구현하는 개체를 쿼리하기 위한 static(Visual Basic의 경우 Shared) 메서드 집합을 제공합니다. 상속 계층 구조System.Object System.Linq.Enumerable 네임스페이스: System.Linq 어셈블리: System.Core(System.Core.dll) 구문public static class Enumerable 설명이 클래스의 메서드는 IEnumerable을 구현하는 데이터 소스를 쿼리하기 위한 표준 쿼리 연산자를 구현합니다. 표준 쿼리 연산자는 LINQ 패턴을 따르며, 모든 .NET 기반 프로그래밍 언어에서 탐색, 필터 및 프로젝션 작업을 나타낼 수 있게 하는 범용 메서드입니다.이 클래스의 메서드는 대부분 IEnumerable을 확장하는 .. 2014. 5. 22.
C#을 이용한 NTP Service using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Net;using System.Net.Sockets; namespace NTPService_Time{ /// /// Static class to receive the time from a NTP server. /// public static class NtpClient { /// /// Gets the current DateTime from time-a.nist.gov. /// /// A DateTime containing the current time. public static DateTime GetNetw.. 2014. 5. 17.