C#/기초
-
[C#]LINQC#/기초 2022. 2. 21. 15:50
Group By using System; using System.Linq; namespace GroupBy { class Profile { public string Name { get; set; } public int Height { get; set; } } class MainApp { static void Main(string[] args) { Profile[] arrProfile = { new Profile(){Name="정우성", Height=186}, new Profile(){Name="김태희", Height=158}, new Profile(){Name="고현정", Height=172}, new Profile(){Name="이문세", Height=178}, new Profile(){Name="하하..
-
[C#]문법C#/기초 2022. 2. 18. 11:14
이것이 C#이다. 책 참조. 4.7 조건 연산자 ?: 조건식 ? 참일_떄의_값 : 거짓일_때의_값 ex) int a =30; string result = a == 30 ? "삼십" : "삼십아님";// result는 삼십 4.8 null 조건부 연산자 ( null이 아니면~~ ?. 실행) null 조건부 연산자 ?. (C#6.0도입) ?. //해당 객체가 null인지 검사하여 그 결과가 참(즉, 객체가 null)이면 그 결과로 null을 반환하고, 그렇지 않은 경우에는 . 뒤에 지정된 멤버를 반환. ex) class Foo { public int member; } Foo foo = null; int? bar; bar = foo?.member;//foo객체가 null이 아니면 member필드에 접근하게 해..
-
WritePixelsC#/기초 2021. 12. 24. 12:15
public void WritePixels (System.Windows.Int32Rect sourceRect, Array pixels, int stride, int offset); Parameters sourceRectInt32Rect The rectangle of the WriteableBitmap to update. pixelsArray The pixel array used to update the bitmap. strideInt32 The stride of the update region in pixels. offsetInt32 The input buffer offset. //The stride value is calculated as the number of bytes per "pixel line..
-
[C#]WPF Serial PortC#/기초 2021. 12. 21. 16:10
연결 후 received함수를 스레드로. 연결까지 스레드로 넘기면 나중에 다시 연결 시도할때 if(!serial.Isopen) 을 걸어도 진입하고 충돌을 일으킴. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Me..
-
[C#] ??, ?. 연산자 ( Nullable) Null 널C#/기초 2021. 12. 16. 15:34
연산자 ?. 및 ?[]피연산자가 null 이 아닌 것으로 평가되었을 때만 멤버 액세스 ?. 또는 요소 액세스 ?[] 연산을 피연산자에게 적용하며, 그렇지 않으면 null 을 반환한다.a가 null로 평가되면 a?.x 또는 a?[x]의 결과는 null이다.a가 null이 아닌 것으로 평가되면 a?.x 또는 a?[x]의 결과는 각각 a.x또는 a[x]의 결과와 같다.Null 조건부 연산자는 단락 연산자이다. 즉 조건부 멤버나 요소 액세스 작업의 한 체인의 작업에서 null을 반환하면 나머지 체인은 실행되지 않는다. 다음 예제에서 A가 null로 평가되면 B가 평가되지 않고, A또는 B가 null로 평가되면 C가 평가되지 않는다.A?.B?.Do(C); ? 기본 처리 방법object tmp = {조건} ? {참..
-
Delegate, Event, ActionC#/기초 2021. 12. 14. 17:10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication42 { public delegate void MyEventHandler(string message); class Publisher { public event MyEventHandler Active; public void DoActive(int number) { if (number % 10 == 0) Active("Active!" + number); else Console.WriteLine(number); } } class Subscriber { st..