'Programming'에 해당되는 글 1786건

  1. 2020.10.05 c# using 키워드, 예외처리
  2. 2020.10.05 c# @문자열
  3. 2020.09.29 winform socket
  4. 2020.09.29 c# conditional attribute
  5. 2020.09.28 mono로 sln 프로젝트 빌드가 되네? 2
  6. 2020.09.23 c# 오버라이드, 하이드, 쉐도우
  7. 2020.09.23 c# 상속
  8. 2020.09.23 c#은 main()이 아니다 Main()이다 -_-
  9. 2020.09.22 c# base, is
  10. 2020.09.22 c# xml 주석
Programming/c# & winform2020. 10. 5. 11:16

c# 프로그래밍 책을 보는데 오랫만에 봐서 그런가 먼가 많이 건너뛰어버린 느낌 ㅠㅠ

스트림에서 갑자기 Dispose() 나오지 않나 StreamReader 클래스도 IDisposable 인터페이스 구현 이런 이야기 나오는것 봐서는

다시 봐야할 것 같다 -_ㅠ

 

아무튼!

using 은 name space를 정의하는데 쓰는 것 뿐만 아니라

내부에서 예외발생시 Dispose() 메소드를 호출해주는 유용한 녀석이라고 한다.

 

아래 예제는 삼항연산자는 아닌거 같은데 다시 봐야겠네..

 

string manyLines=@"This is line one
This is line two
Here is line three
The penultimate line is line four
This is the final, fifth line.";

using (var reader = new StringReader(manyLines))
{
    string? item;
    do {
        item = reader.ReadLine();
        Console.WriteLine(item);
    } while(item != null);
}

 

c# 8.0 이후

string manyLines=@"This is line one
This is line two
Here is line three
The penultimate line is line four
This is the final, fifth line.";

using var reader = new StringReader(manyLines);
string? item;
do {
    item = reader.ReadLine();
    Console.WriteLine(item);
} while(item != null);

[링크 : https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/using-statement]

 

+

 

IDisposable.Dispose 메서드
관리되지 않는 리소스의 확보, 해제 또는 다시 설정과 관련된 애플리케이션 정의 작업을 수행합니다.

[링크 : https://docs.microsoft.com/ko-kr/dotnet/api/system.idisposable.dispose?view=netcore-3.1]

'Programming > c# & winform' 카테고리의 다른 글

c# out  (0) 2020.10.07
c# 타입? 변수명;  (0) 2020.10.05
c# @문자열  (0) 2020.10.05
winform socket  (0) 2020.09.29
c# conditional attribute  (0) 2020.09.29
Posted by 구차니
Programming/c# & winform2020. 10. 5. 11:10

@는 수 많은 \ (escape)의 향연에서 벗어날수 있게 해주는 마법의 키워드이다.

string filename1 = @"c:\documents\files\u0066.txt";
string filename2 = "c:\\documents\\files\\u0066.txt";

[링크 : https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/tokens/verbatim]

 

어떻게 보면 pre 태그 같은 느낌마저 주네?

[링크 : https://docs.microsoft.com/ko-kr/.../convert-between-regular-string-verbatim-string?view=vs-2019]

'Programming > c# & winform' 카테고리의 다른 글

c# 타입? 변수명;  (0) 2020.10.05
c# using 키워드, 예외처리  (0) 2020.10.05
winform socket  (0) 2020.09.29
c# conditional attribute  (0) 2020.09.29
mono로 sln 프로젝트 빌드가 되네?  (2) 2020.09.28
Posted by 구차니
Programming/c# & winform2020. 9. 29. 14:28

비동기는 callback을 이용하고

동기는 무한대기 하는 것으로 구현되어 있다.

 

[링크 : https://docs.microsoft.com/en-us/dotnet/framework/network-programming/socket-code-examples]

   [링크 : https://docs.microsoft.com/.../asynchronous-server-socket-example]

   [링크 : https://docs.microsoft.com/.../asynchronous-client-socket-example]

   [링크 : https://docs.microsoft.com/.../synchronous-server-socket-example]

   [링크 : https://docs.microsoft.com/.../synchronous-client-socket-example]

 

그나저나 동기, 비동기는 여전히 헷갈리네..

동기는 추상적인 구분인데 어떠한 행위를 같이 하냐 안하냐 라고 봐야 하는건가?

[링크 : https://okky.kr/article/442803]

 

+

동기/블러킹 방식으로 구현

 

NetworkStream클래스는 Stream 차단 모드에서 소켓을 통해 데이터를 보내고 받는 메서드를 제공 합니다.

[링크 : https://docs.microsoft.com/ko-kr/dotnet/api/system.net.sockets.networkstream?view=netcore-3.1]

[링크 : https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.networkstream?view=netcore-3.1]

'Programming > c# & winform' 카테고리의 다른 글

c# using 키워드, 예외처리  (0) 2020.10.05
c# @문자열  (0) 2020.10.05
c# conditional attribute  (0) 2020.09.29
mono로 sln 프로젝트 빌드가 되네?  (2) 2020.09.28
c# 오버라이드, 하이드, 쉐도우  (0) 2020.09.23
Posted by 구차니
Programming/c# & winform2020. 9. 29. 11:47

effective c#에서 item #4 내용

 

#if defined(__DEBUG__)
#endif

류의 preprocessor 쪽 문장들은 유지보수도 힘드니까

 

[Conditional("DEBUG")]

로 깔끔하게 조건에 따라서 릴리즈 모드에서는 배제 되도록 하는 문구.

어떻게 보면.. Java의 annotation 느낌이긴 하다?

 

해당 조건을 쓰기 위해서는 /define 명령을 이용해서 미리 선언을 해주어야 한다.

gcc에서 -D 쓰는 느낌? ㅋ

컴파일러 명령줄 옵션을 사용 합니다. 예를 들어 /define: DEBUG입니다.

[링크 : https://docs.microsoft.com/ko-kr/dotnet/api/system.diagnostics.conditionalattribute?view=netcore-3.1]

'Programming > c# & winform' 카테고리의 다른 글

c# @문자열  (0) 2020.10.05
winform socket  (0) 2020.09.29
mono로 sln 프로젝트 빌드가 되네?  (2) 2020.09.28
c# 오버라이드, 하이드, 쉐도우  (0) 2020.09.23
c# 상속  (0) 2020.09.23
Posted by 구차니
Programming/c# & winform2020. 9. 28. 11:13

오.. 신기신기..

어떻게 빌드하지?하다가

아무생각 없이 그냥 해당 프로젝트 디렉토리 들어가니 mono develop 아이콘이 똭!

더블 클릭해서 실행하니 mono develop  가 뜨고 빌드 옵션을 Debug에서 Release로 바꾸고

빌드하니

 

띠용.. PE32 executable 이 뜬다.

~/ar/bin/Release$ file *
ar.exe:        PE32 executable (GUI) Intel 80386 Mono/.Net assembly, for MS Windows
ar.exe.config: XML 1.0 document, UTF-8 Unicode (with BOM) text, with CRLF line terminators
ar.pdb:        Microsoft Rosyln C# debugging symbols version 1.0

 

물론 윈도우에서 프로젝트 파일 자체를 그대로 전송해 왔기 때문에

Deub로 가면 아래와 같이 나오는데 pdb는 메시지가 조금 다른데 exe는 리눅스 상에서 인식하는 포맷이 동일하게 나온다.

~/ar/bin/Debug$ file *
ar.exe:        PE32 executable (GUI) Intel 80386 Mono/.Net assembly, for MS Windows
ar.exe.config: XML 1.0 document, UTF-8 Unicode (with BOM) text, with CRLF line terminators
ar.pdb:        MSVC program database ver 7.00, 512*115 bytes

 

그나저나 4.7의 모든 것 이라고 해놓고

WPF, WWF 그리고 제한된 WCF 그리고 제한된 ASP.NET 비동기 stack을 제외한... (야이!!!)

Everything in .NET 4.7 except WPF, WWF, and with limited WCF and limited ASP.NET async stack.

[링크 : https://www.mono-project.com/docs/about-mono/compatibility/]

 

WWF는 처음 듣네? 검색해보니 레슬링이 왜 나오냐 ㅠㅠ

Windows Workflow Foundation

[링크 : https://docs.microsoft.com/ko-kr/dotnet/framework/windows-workflow-foundation/]

 

그냥 무난하게 winform으로 작성한건 그럼 리눅스에서 빌드하고 실행이 가능한데

GUI자체는 노가다 하거나 visual studio community에서 하는수 밖에 없나?

'Programming > c# & winform' 카테고리의 다른 글

winform socket  (0) 2020.09.29
c# conditional attribute  (0) 2020.09.29
c# 오버라이드, 하이드, 쉐도우  (0) 2020.09.23
c# 상속  (0) 2020.09.23
c#은 main()이 아니다 Main()이다 -_-  (0) 2020.09.23
Posted by 구차니
Programming/c# & winform2020. 9. 23. 11:33

변수에는 오버라이드 개념이 없고

변수에게 있어서 동일 이름이라 숨겨지는 건 하이드라고 표현하는 듯.

기존의 scope를 다른게 표현 하는 느낌이기도 하고(객체로 확장시키면서)...

조금 더 봐야 할 듯?

 

섀도잉(shadowing)

클래스내 멤버 변수가 멤버 메소드내에 선언한 변수에 의해 가려지는 경우

 

하이딩(hiding)

상속 관계에서 상위 객체의 변수가 하위 객체에서 선언한 변수에 의해 가려지는 경우

 

오버라이드(overriding)

상속 관계에서 상위 객체의 메소드가 하위 객체에서 선언한 메소드에 의해 가려지는 경우

해당 내용에 다음과 같은 설명이 있습니다.

case 2:
When you override a member variable in a child class (actually its hiding, not overriding),
which version of that variable will be called depends on the reference, the object, unlike method lookup. 
 
In your sample code, variable a and b are not actually member variable,
they are class variable since static.
Lets change the sample code a bit,
making the 'a' in class 'A' public and adding some test code in main. 

즉, 변수는 override되는 것이 아니라 hiding되는 것이며 dynamic하게 lookup되는 것이 아닙니다.
한 마디로, B의 a는 A의 a를 그저 hiding하는 것이고 A의 a와는 별개의 변수이며,
getA는 자기가 정의된 시점의 a를 a로 생각하게 됩니다. B의 a에 대해서는 아예 모르죠.

[링크 : https://kldp.org/node/110902]

'Programming > c# & winform' 카테고리의 다른 글

c# conditional attribute  (0) 2020.09.29
mono로 sln 프로젝트 빌드가 되네?  (2) 2020.09.28
c# 상속  (0) 2020.09.23
c#은 main()이 아니다 Main()이다 -_-  (0) 2020.09.23
c# base, is  (0) 2020.09.22
Posted by 구차니
Programming/c# & winform2020. 9. 23. 11:10

sealed 는 java의  final 역활.(더 이상 상속을 할 수 없도록)

 

set, get 키워드

java에서 setter/getter의 축약 문법 느낌?

변수에 대해서 사용하며, set의 경우 value 라는 생략된 인자를 받아서 사용

private string name = "John";
public string Name
{
    get
    {
        return name;
    }
    set
    {
       name = value;
    }
}

// ...
static void Main(string[] args)
{
    MyClass mc = new MyClass();
    Console.WriteLine(mc.Name);
    mc.Name = "Bree";
    Console.WriteLine(mc.Name);
}

[링크 : https://blog.hexabrain.net/142]

 

+

2020.09.29

Effective c#을 읽다 보니 property 라고 표현 함.

[링크 : https://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/classes-and-structs/properties]

'Programming > c# & winform' 카테고리의 다른 글

mono로 sln 프로젝트 빌드가 되네?  (2) 2020.09.28
c# 오버라이드, 하이드, 쉐도우  (0) 2020.09.23
c#은 main()이 아니다 Main()이다 -_-  (0) 2020.09.23
c# base, is  (0) 2020.09.22
c# xml 주석  (0) 2020.09.22
Posted by 구차니
Programming/c# & winform2020. 9. 23. 10:37

국룰을 이렇게 파괴하는 MS 이대로 좋은가?!

아무튼 함수이름들도 죄다 Capitalize 했으니 Main()도 당연한거긴 한데..

하긴 한데.. 꽁기꽁기 하네?

 

$ csc cons.cs 
Microsoft (R) Visual C# Compiler version 3.6.0-4.20224.5 (ec77c100)
Copyright (C) Microsoft Corporation. All rights reserved.

error CS5001: Program does not contain a static 'Main' method suitable for an entry point

 

아래 코드를 테스트 하는데 너무 단순해서 그런가.. Child()와 Child() : base()의 실행 결과에 차이는 없다.

단순히 명시적으로 해주었을뿐 어짜피 부모 생성자 실행 후 자식 생성자를 실행 하는 것은 변하지 않기 때문일 듯.

using System;

class Program
{
	class Parent
	{
		public Parent() {Console.WriteLine("부모 생성자");}
	}
	
	class Child:Parent
	{
//		public Child() : base()
		public Child()
		{
			Console.WriteLine("자식 생성자");}
	}

	static void Main(string[] args)
	{
		Child child = new Child();
	}
}

[링크 : https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/base]

'Programming > c# & winform' 카테고리의 다른 글

c# 오버라이드, 하이드, 쉐도우  (0) 2020.09.23
c# 상속  (0) 2020.09.23
c# base, is  (0) 2020.09.22
c# xml 주석  (0) 2020.09.22
c# 프로그래밍, 문법 공부(문자열)  (0) 2020.09.22
Posted by 구차니
Programming/c# & winform2020. 9. 22. 17:20

java의 super 키워드와 동일한 느낌?

 

[링크 : https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/base]

[링크 : https://blanedil.tistory.com/2]

[링크 : https://www.tutorialspoint.com/equivalent-of-java-super-keyword-in-chash]

 

+ 2020.09.23

ms 문서에서 보는데 base 아래 this가 있어서 무슨 차이인가 보니..

base는 상속관계에서, this는 클래스내 메소드에서 클래스 변수에 접근할때 사용하는 것으로 범위가 다른 경우에 대해서

서로 다른 용어로 정의를 한 것으로 보인다.

base 키워드는 파생 클래스 내에서 기본 클래스의 멤버에 액세스하는 데 사용됩니다
this 키워드는 클래스의 현재 인스턴스를 가리키며 확장 메서드의 첫 번째 매개 변수에 대한 한정자로도 사용됩니다.

[링크 : https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/this]

 

is는 instanceof에 상응할 듯.

[링크 : https://stackoverflow.com/questions/18147211/c-sharp-is-operator-alternative-in-java/18147246]

'Programming > c# & winform' 카테고리의 다른 글

c# 상속  (0) 2020.09.23
c#은 main()이 아니다 Main()이다 -_-  (0) 2020.09.23
c# xml 주석  (0) 2020.09.22
c# 프로그래밍, 문법 공부(문자열)  (0) 2020.09.22
c# 교과서 표준 입출력 등  (0) 2020.09.21
Posted by 구차니
Programming/c# & winform2020. 9. 22. 16:33

특이한 주석이 존재하네?

/// 일 경우에는 xml 주석인데 몇가지 태그가 존재한다.

어떤 의미로는.. doxygen 을 xml로 해놓은것 같긴한데...

결과물에 어떻게 나오는지 궁금하네?

// Adds two integers and returns the result
/// <summary>
/// Adds two integers and returns the result.
/// </summary>
/// <returns>
/// The sum of two integers.
/// </returns>
/// <example>
/// <code>
/// int c = Math.Add(4, 5);
/// if (c > 10)
/// {
///     Console.WriteLine(c);
/// }
/// </code>
/// </example>
public static int Add(int a, int b)
{
    // If any parameter is equal to the max value of an integer
    // and the other is greater than zero
    if ((a == int.MaxValue && b > 0) || (b == int.MaxValue && a > 0))
        throw new System.OverflowException();

    return a + b;
}

 

[링크 : https://docs.microsoft.com/ko-kr/dotnet/csharp/codedoc]

  [링크 : http://blog.daum.net/clerkurt/251]

'Programming > c# & winform' 카테고리의 다른 글

c#은 main()이 아니다 Main()이다 -_-  (0) 2020.09.23
c# base, is  (0) 2020.09.22
c# 프로그래밍, 문법 공부(문자열)  (0) 2020.09.22
c# 교과서 표준 입출력 등  (0) 2020.09.21
c# 교과서 - 키워드 정리  (0) 2020.09.21
Posted by 구차니