본문 바로가기

C#7

C# Partial class 를 사용하는 이유 using System; using System.Collections.Generic; namespace hello{ public partial class aaaa { }} C#에는 partial 클래스 라는 것이 있다. 다음의 몇가지 경우에 partial 클래스를 생성한다. 1. Windows Form 응용 프로그램을 만들 때프로젝트를 생성하면 자동으로 partial class 가 생성된다. 2. 다수의 개발자의 개발windows 폼 application의 화면부분 , 로직 부분을 동시에 작업 할 때도 쓰인다.한 파일에서 작업 할 때 생기는 conflict를 막을 수 있다. 3. partial 로 함수가 정의된 클래스와 선언 된 클래스를 분리하는 경우 2019. 3. 18.
ASP.net 정리 컨트롤러에서 화면으로 model 전달하는 방법 public IActionResult Contact() { ViewData["Message"] = "Your contact page."; var viewModel = new Address() { Name = "Microsoft", Street = "One Microsoft Way", City = "Redmond", State = "WA", PostalCode = "98052-6399" }; return View(viewModel); } View(); 함수의 괄호 안에 모델 전달한다. 뷰만 전달하는 방법return View("Views/Home/About.cshtml"); 뷰와 모델을 함께 전달하려면 아래와 같이 한다. return View("Orders", .. 2019. 2. 7.
C# const 와 readonly C# 에서는 두 가지의 상수를 지원한다. const , readonly 차이는 이렇다. const - 컴파일시 할당 , 값을 아예 바꿀 수 없다. 자동으로 static 으로 사용 됨 ( 전역 상수로 쓰이는 것 같은 느낌 ) readonly - 런타임 할당 , 객체 생성시 생성자로 할당 가능하다. static 으로 사용 안 됨 ( 객체 상수로 쓰이는 것 같은 느낌 ) 2019. 2. 1.
asp.net 기초 // GET: Movies/Delete/5 public async Task Delete(int? id) { if (id == null) { return NotFound(); } var movie = await _context.Movie .FirstOrDefaultAsync(m => m.Id == id); if (movie == null) { return NotFound(); } return View(movie); //View() = 메소드와 같은 이름으로 뷰를 리턴한다. } 서버에서 뷰로 값을 보내는 방법 2019. 1. 31.
C# 주소에 요청 보내고 json 값 받기 using System.Net; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); button1.Click += request; } private void request(object sender, EventArgs e) { using(WebClient wc = new WebClient()) { var json = new WebClient().DownloadString("https://en.wikipedia.org/w/api.php?action=parse§ion=0&prop=text&format=json&page=pizza"); Console.WriteLine(j.. 2019. 1. 4.