반응형

1. 텍스트 파일을 한번에 한줄씩 읽는 방법.

int counter = 0;  
  
// Read the file and display it line by line.  
foreach (string line in System.IO.File.ReadLines(@"c:\test.txt"))
{  
    System.Console.WriteLine(line);  
    counter++;  
}
  
System.Console.WriteLine("There were {0} lines.", counter);  
// Suspend the screen.  
System.Console.ReadLine();

 File 클래스의 ReadLines 메서드를 사용하여 텍스트 파일 내용을 한번에 한줄씩 문자열로 읽어옵니다. 

foreach문을 통해 각 라인에서 읽어온 데이터를 처리할 수 있습니다. 

 

2. 파일 append 함수

File.AppendAllText([FILE PATH], [DATA] );
//띄어 써야 할 경우 
//[DATA] + "\n"

 

반응형
반응형

Namespace : Microsoft.Win32
Assembly : PresentationFramework.dll

download site : https://ko.dll-files.com/presentationframework.dll.html

attribute value : String
filter가 들어가 있는 string 값

exception : ArgumentException 

 

code1 : empty/null
OpenFileDialog dlg = new OpenFileDialog();
// Show all files
dlg.Filter = string.Empty; //dlg.Filter = null;
dlg.ShowDialog();
code2 ( filter 1 )
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Word Documents
dlg.Filter = "Json File|*.json";
dlg.ShowDialog();
code3 ( filter n )
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Office Files
dlg.Filter = "Office Files|*.doc;*.xls;*.ppt";

dlg.ShowDialog();
code 4 ( all file )
OpenFileDialog dlg = new OpenFileDialog();

// Filter by All Files
dlg.Filter = "All Files|*.*";

dlg.ShowDialog();
code5 ( filter n )
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations 
//           OR Office Files 
//           OR All Files
dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" +
             "|Office Files|*.doc;*.xls;*.ppt" +
             "|All Files|*.*";

dlg.ShowDialog();

표시되는 파일 형식의 하위 집합을 지정하려면 필터링할 하나 이상의 파일 형식을 지정하는 문자열 값(필터 문자열)으로 속성을 설정합니다Filter. 
다음은 필터 문자열의 예상 형식을 보여줍니다.

FileType1[[|FileType2]...[|FileTypeN]]

다음 형식을 사용하여 각 파일 형식을 설명합니다.

Label|Extension1[[;Extension2]...[;ExtensionN]]

레이블 부분은 다음과 같이 파일 형식을 설명하는 사람이 읽을 수 있는 문자열 값입니다.
각 파일 형식은 하나 이상의 확장 명에서 설명해야 합니다. 
둘 이상의 확장을 사용하는 경우 각 확장을 세미콜론(";")으로 구분해야 합니다. 

"java file"|"*.jave"
"Json file"|"*.json"
"c file"|"*.c"
"c# file"|"*.cs"
"office file"|"*.doc;*.xls;*.ppt"
"모든 파일"|"*.*"

적용 대상 
제품 버전
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7 Preview 4

참고 사이트 : https://docs.microsoft.com/ko-kr/dotnet/api/microsoft.win32.filedialog.filter?view=windowsdesktop-6.0

반응형
반응형
TSource 

generic type parameter

public static IEnumerable<TSource> Union<TSource>

LINW method에서 일반적으로 다음의 파라메터를 사용한다. 

Tsource : element tpye of the input ( source )

TResult : element tpye of the output ( result )

TKey : element type of a key used for things like grouping 

TElement : element type of an intermediate sequence 

반응형

+ Recent posts