본문 바로가기

프로그래밍

C# 리스트 조회, 리스트 정렬 StreamReader file = new StreamReader("input.txt"); int size = Int32.Parse(file.ReadLine()); List list = new List(); while (!file.EndOfStream) { list.Add(file.ReadLine()); } //list.Sort(); List newlist = new List(); for (int i = 0; i < list.Count; i++) { if (!newlist.Contains(list[i])) { newlist.Add(list[i]); } } newlist.Sort(delegate(string a, string b) { if (a.Length < b.Length) return -1; else.. 더보기
C# 문자열 파싱 parsing split StreamReader file = new StreamReader("input.txt"); int size = 0; //List list = new List(); while (!file.EndOfStream) { string s=file.ReadLine(); string[] token = s.Split(' '); size += token.Length; } file.Close(); 더보기
C# 문자열 Mid,Left,Right public string Mid(string sString, int nStart, int nLength) { string sReturn; --nStart; if (nStart sString.Length) { nLength = sString.Length; } sReturn = sString.Substring(sString.Length - nLength,nLength); return sReturn; } 더보기
C# lock using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace @lock { class Account { private Object thisLock = new Object(); int balance; Random r = new Random(); public Account(int initial) { balance = initial; } int Withdraw(int amount) { // This condition never is true unless the lock statement // is comm.. 더보기
C# 명령줄 인수 class CommandLine { static void Main(string[] args) { // The Length property provides the number of array elements System.Console.WriteLine("parameter count = {0}", args.Length); for (int i = 0; i < args.Length; i++) { System.Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]); } } } class CommandLine2 { static void Main(string[] args) { System.Console.WriteLine("Number of command line parameters .. 더보기
C# 비트 연산 using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace bitByte { class Program { static void PrintBits(BitArray ba) { for (int i = 0; i < ba.Count; i++) { Console.Write(ba[i] ? "1" : "0"); } Console.WriteLine(); } static void Main(string[] args) { // (// (1) 한 byte 를 Hex 문자로 변환하는 방법법 byte bbb1 = 0xFE.. 더보기
C# 소켓 클라이언트 socket client using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SocketClient { class Program { public class StateObject { // Client socket. public Socket workSocket = null; // Size of receive buffer. public const int BufferSize = 256; // Receive buffer. public byte[] .. 더보기
C# 소켓 서버 socket server using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SocketServer { class Program { static void Main(string[] args) { AsynchronousSocketListener.StartListening(); } } // State object for reading client data asynchronously public class StateObject { // Clien.. 더보기
C# 스레드 thread using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace thread { public class ServerClass { // The method that will be called when the thread is started. public void InstanceMethod() { Console.WriteLine( "ServerClass.InstanceMethod is running on another thread."); // Pause for a moment to provide a dela.. 더보기
C# 타이머 Timer using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; using Net.Common; using System.Net; using System.IO; using System.Net.Json; namespace MobilePushCheckAgent { public partial class .. 더보기