c#
-
Data gridvie to Execelc# 2017. 5. 8. 18:17
using System; using System.Data; using System.Windows.Forms; using System.Data.SqlClient; using Excel = Microsoft.Office.Interop.Excel; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string connectionString = "Data Source=.;Initial Catalog=pubs;Integrated Security=True"; s..
-
AppConfig 사용방법c# 2017. 5. 8. 10:07
using System;using System.Configuration; namespace ConsoleApplication1{ class Program { static void Main(string[] args) { ReadAllSettings(); ReadSetting("Setting1"); ReadSetting("NotValid"); AddUpdateAppSettings("NewSetting", "May 7, 2014"); AddUpdateAppSettings("Setting1", "May 8, 2014"); ReadAllSettings(); Console.ReadKey(); } static void ReadAllSettings() { try { var appSettings = Configurati..
-
비동기 방식의 파일 복사(async)c# 2017. 5. 7. 17:39
private async Task CopyAsync(string fromPath, string ToPath) { btnSyncyCopy.Enabled = false; long totalCopied = 0; using (FileStream fromStream = new FileStream(fromPath, FileMode.Open)) { using (FileStream toStream = new FileStream(ToPath,FileMode.Create)) { byte[] buffer = new byte[1024 * 1024]; int nRead = 0; while ((nRead= await fromStream.ReadAsync(buffer,0,buffer.Length))!=0) { await toStr..
-
파일 다루기2c# 2017. 5. 6. 16:31
Stream stream1 = new FileStream("a.dat",FileMode.Create) //새파일 생성Stream stream2 = new FileStream("a.dat",FileMode.Open) // 파일 열기Stream stream3 = new FileStream("a.dat",FileMode.OPenCreate) //파일을 열거나 없으면 생성해서 열기Stream stream4 = new FileStream("a.dat",FileMode.Turncate) // 파일을 비워서 열기Stream stream5 = new FileStream("a.dat",FileMode.Append) // 덧붙이기 모드로 열기 1.Stream using System;using System.Collectio..
-
파일 다루기1c# 2017. 5. 6. 14:39
File,Diretory: 정적 메소드 제공, 한 두가지 기능을 다룰때 FileInfo, DirectoryInfo : 인스턴트 메소드 제공 기능 File FileInfo 생성 FileStream fs=File.Create("a.dat") FileInfo file = new FileInfo("a.dat") FileStram fs = file.Create(); 복사 File.Copy("a.dat","b.dat") FileInfo src = new FileInfo("a.dat"); FlleInfo des = src.Copy(To"b.dat"); 삭제 File.Delete("a.dat") FileInfo file = new FIleInfo("a.dat")file.Delete(); 이동 FIle.Move("a.d..
-
out:출력 전용 매개변수c# 2017. 5. 6. 12:03
out는 참조형 변수 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace UsingOut{ class Program { static void Divide(int a, int b, out int quo, out int rem) { quo = a / b; rem = a % b; } static void Main(string[] args) { int a = 30; int b = 3; int c; int d; Divide(a, b, out c, out d); Console.WriteLine("a:{0}, b:{1}, a/b:{2}, a%b:{3}"..
-
데이터 타입c# 2017. 5. 6. 11:55
Nullable형식 :변수에 값이 할당 되지 않으면 null을 할당하세요.데이터형식? 변수이름: int ?a =null; ------------------int? a = null; Console.WriteLine(a.Hasvalue) ; // FasleConsole.WriteLine(a !=null); // False a=3; Console.WritLine(a.HasValue); //TrueConsole.WriteLine(a != null) //TrueConsole.WriteLine(a.value) //3 Var형식-Compile가 자동으로 변식 형식을 지정해 줍니다.-var형식은 반드시 선언과 함께 초기화 해 주어야 합니다.-var형식은 반드시 지역변수로만 사용할 수 있습니다. var a =3;var ..