'Programming'에 해당되는 글 1762건

  1. 2020.10.13 .net core와 .net framework 차이 - winform menustrip
  2. 2020.10.12 winform 에서 이미지 넣기
  3. 2020.10.08 c# strong type langugae
  4. 2020.10.08 c# delagate 대리자
  5. 2020.10.07 c# out
  6. 2020.10.05 c# 타입? 변수명;
  7. 2020.10.05 c# using 키워드, 예외처리
  8. 2020.10.05 c# @문자열
  9. 2020.09.29 winform socket
  10. 2020.09.29 c# conditional attribute
Programming/c# & winform2020. 10. 13. 14:33

메뉴를 넣는데 인터넷 검색해보니

예전 MFC 처럼 메뉴를 클릭클릭하면서 생성해낼수 있을줄 알았는데

안되서 혹시? 라는 마음에 해보니

 

.net core는 메뉴는 생성되지만 개별 메뉴는 일일이 코딩으로 해야 한다면

 

.net framwork는 기존대로 생성이 가능하다.

 

멀티플랫폼 갈게 아니라면 .net core로 굳이 가야 하나 라는 생각이 드네..

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

mono .net framework 실행  (0) 2020.10.13
.net core/.net framework 컨트롤 차이  (0) 2020.10.13
winform 에서 이미지 넣기  (0) 2020.10.12
c# strong type langugae  (0) 2020.10.08
c# delagate 대리자  (0) 2020.10.08
Posted by 구차니
Programming/c# & winform2020. 10. 12. 13:55

VS2019 에서 정상적으로 넣는법은 찾지 못했고

Image 클래스를 이용해 넣은 후 컴파일 하면 자동으로 Form1.resx 파일에 추가되긴 한다.

 

[링크 : https://www.dotnetperls.com/picturebox]

[링크 : https://stackoverflow.com/questions/19910172/how-to-make-picturebox-transparent]

 

+ 2020.10.13

winform .net core로 해서 그런걸까?

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

.net core/.net framework 컨트롤 차이  (0) 2020.10.13
.net core와 .net framework 차이 - winform menustrip  (0) 2020.10.13
c# strong type langugae  (0) 2020.10.08
c# delagate 대리자  (0) 2020.10.08
c# out  (0) 2020.10.07
Posted by 구차니
Programming/c# & winform2020. 10. 8. 08:14

 

c#을 강형 언어라고 봐야 할진 모르겠지만

최소한 strongly typed language 라고 해놨으니.. 그리고 문법적으로도 상당 부분이 c에 비해서

explicit 하지 않고 implcit 하게 변형을 하도록 강제하고 있어 최대한

컴파일 타임에 잡아내도록 해놨으니 같은거라고 봐야 하나 아닌가 조금 고민되네?

 

 

C#은 강력한 형식의 언어입니다.

[링크 : http://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/types/]

 

C# is a strongly typed language.

[링크 : https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/]

 

[링크 : https://ahnheejong.name/articles/types-basic-concepts/]

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

.net core와 .net framework 차이 - winform menustrip  (0) 2020.10.13
winform 에서 이미지 넣기  (0) 2020.10.12
c# delagate 대리자  (0) 2020.10.08
c# out  (0) 2020.10.07
c# 타입? 변수명;  (0) 2020.10.05
Posted by 구차니
Programming/c# & winform2020. 10. 8. 08:13

함수포인터의 문법화라는 느낌

node.js에서 흔하게 사용하던 그 문법

 

그런데 람다가 있는데 굳이 delegate 라는걸 또 표현하는 이유는 좀 모르겠다.

두개가 용도가 다른가?

 

[링크 : http://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/delegates/]

[링크 : https://docs.microsoft.com/ko-kr/dotnet/standard/delegates-lambdas]

 

반대로.. delegate에 대응되는 다른 언어의 용어를 찾아봐야겠다.

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

winform 에서 이미지 넣기  (0) 2020.10.12
c# strong type langugae  (0) 2020.10.08
c# out  (0) 2020.10.07
c# 타입? 변수명;  (0) 2020.10.05
c# using 키워드, 예외처리  (0) 2020.10.05
Posted by 구차니
Programming/c# & winform2020. 10. 7. 17:05

함수 인자로 out을 사용하면 기존의 c 언어에서 포인터로 값을 빼내오듯 사용이 가능하다.

 

OutArgExample() 함수에서도 out 을 이용하여 number 인자는 입력이 아닌 출력으로 사용한다고 명시하고

해당 함수를 호출 할때도 out initializeInMethod 라는 변수가 출력용 변수임을 명시한다.

 

 

int initializeInMethod;
OutArgExample(out initializeInMethod);
Console.WriteLine(initializeInMethod);     // value is now 44

void OutArgExample(out int number)
{
    number = 44;
}

 

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

 

기존의 C로 보면 이걸 문법적으로 표현해주는 느낌이다.

int initializeInMethod;
OutArgExample(&initializeInMethod);
Console.WriteLine(initializeInMethod);     // value is now 44

void OutArgExample(int *number)
{
    *number = 44;
}

[링크 : https://dojang.io/mod/page/view.php?id=550]

 

+

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

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

 

+

2020.10.14

unsafe 옵션과 키워드를 사용해서 사용은 가능하다

using System;

class Touttest
{
	static void Main()
	{
		unsafe{
		int initializeInMethod;
		OutArgExample(&initializeInMethod);
		Console.WriteLine(initializeInMethod);     // value is now 44

		void OutArgExample(int *number)
		{
			*number = 44;
		}
		}
	}
}
$ csc /unsafe out2.cs

unsafe 옵션과 키워드를 사용해서 사용은 가능하다

 

 

+

포인터는 기본적으로 막히고..

out2.cs(8,17): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
out2.cs(8,3): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
out2.cs(13,4): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
out2.cs(13,13): error CS0266: Cannot implicitly convert type 'int' to 'int*'. An explicit conversion exists (are you missing a cast?)
out2.cs(13,4): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
out2.cs(11,22): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context

 

/unsafe 옵션을 주지 않고 빌드하면 경고가 아닌 에러가 발생한다 ㄷㄷ

out2.cs(7,3): error CS0227: Unsafe code may only appear if compiling with /unsafe

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

c# strong type langugae  (0) 2020.10.08
c# delagate 대리자  (0) 2020.10.08
c# 타입? 변수명;  (0) 2020.10.05
c# using 키워드, 예외처리  (0) 2020.10.05
c# @문자열  (0) 2020.10.05
Posted by 구차니
Programming/c# & winform2020. 10. 5. 15:05

발단은.. 여기 이녀석.

string? item;

이게 무언가 했는데... string* item; 처럼 보려고 하니 보이기도 하고?

 

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]

 

 

변수가 Nullable<T> 형으로 컴파일러에게 알려주는 역할(?) 라는데..

 

class Program
{
    static void Main(string[] args)
    {
        Int32? x;
        Nullable<Int32> y;
    }
}

[링크 : https://gunnarpeipman.com/csharp-question-marks/]

 

 

 

읽어봐도 무슨 소리인지 모르겠네 ㅠㅠ

형식은 값을 할당 하거나 할당할 수 있는 경우 null을 허용 하는 것으로 간주 됩니다 null . 즉, 형식에 값이 없음을 의미 합니다. 기본적으로와 같은 모든 참조 형식은 nullable 이지만 String 와 같은 모든 값 형식은 Int32 이 아닙니다.

C # 및 Visual Basic에서는 값 형식 다음에 표기법을 사용 하 여 값 형식을 nullable로 표시 합니다 ? . 예를 들어 int? c #에서 또는 Integer? Visual Basic는 할당할 수 있는 정수 값 형식을 선언 null 합니다.

Nullable<T>참조 형식은 의도적으로 null을 허용 하므로 구조체는 값 형식만 nullable 형식으로 사용 하도록 지원 합니다.

Nullable클래스는 구조체를 보완 하도록 지원 합니다 Nullable<T> . Nullable클래스는 nullable 형식의 내부 형식 및 내부 값 형식이 제네릭 비교 및 같음 연산을 지원 하지 않는 nullable 형식 쌍에 대 한 비교 및 같음 연산을 지원 합니다.

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

 

 

한글로 봐도 모르는데 영어로 본다고 알리가 있냐!!! ㅠㅠ

A type is said to be nullable if it can be assigned a value or can be assigned null, which means the type has no value whatsoever. By default, all reference types, such as String, are nullable, but all value types, such as Int32, are not.

In C# and Visual Basic, you mark a value type as nullable by using the ? notation after the value type. For example, int? in C# or Integer? in Visual Basic declares an integer value type that can be assigned null.

The Nullable class provides complementary support for the Nullable<T> structure. The Nullable class supports obtaining the underlying type of a nullable type, and comparison and equality operations on pairs of nullable types whose underlying value type does not support generic comparison and equality operations.

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

 

 

현재까지 결론

string은 NULL이 의미를 지니는 타입이기에 ?를 써서 Nullable class를 사용할 수 있는데

string? item;

은 그냥 nullable string 변수를 선언했다고 보면된다.

 

 

+

정작 빌드해보면 string? 으로 하면 경고가 뜨고 string으로 하면 경고가 안뜨는데 실행결과는 동일하다.

 

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

using.cs(18,11): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

 

먼가 너무 파고들어서 산으로 가는건가? ㅠㅠ

변수 이름 뒤에 null 허용 연산자 !를 사용하여 이 동작을 재정의할 수 있습니다. 예를 들어 name 변수가 null이 아닌 것으로 알고 있는데 컴파일러 경고가 발생하는 경우 다음 코드를 작성하여 컴파일러 분석을 재정의할 수 있습니다.

name!.Length;

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

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

c# delagate 대리자  (0) 2020.10.08
c# out  (0) 2020.10.07
c# using 키워드, 예외처리  (0) 2020.10.05
c# @문자열  (0) 2020.10.05
winform socket  (0) 2020.09.29
Posted by 구차니
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 구차니