[pluralsight] 플러랄사이트 C#강의 1&2&3&4

IT/Programming|2020. 9. 22. 12:14

 


플러랄 사이트 C# 강의

Scott Allen 기본 C# 강의는 12시간 정도 되는 것 같다.

 

전체적인  Contents :  

 

 

친구가 엄청나게 추천해줘서 바로 수업 들어봤다.

 

 

강의 1 &2  

 

Course overview 

Introducing C# and. NET 

 

전체적으로 C#이 뭔지 설명해주고  기본 프로젝트 시작 + VS code 사용법 그리고 중요한 디버깅 하는 법 까지 알려줬다.

 

강의 중  내가 생각했을 때 중요한 부분 : 

위에는 terminal에서 프로젝트 시작하는 방법 -  

그냥 쉽게 visual studio / visual studio code에서도 쉽게 시작할 수는 있다. 

virtual machine -ubuntu 같은 곳에서는 위에서 하는 방법으로 사용할 수 있는 듯? 

 

 

 

 

VIsual Studio에서 C#이라고 찾아서 패키지를 다운로드하여서 사용한다. 

 

 

 

using System;

namespace GradeBook
{
    class Program
    {
        static void Main(string[] args)
        {

            if (args.Length > 0)
            {
                Console.WriteLine("Hello" + args[0] + "!");
                Console.WriteLine($"Hello ,{args[0]} !");// 두개다 같은 result
            }
            else
            {
                Console.WriteLine("Hello stranger!");
            }
        }
    }
}

console.writeline에서 parameter에 따라  Hello 하고 이름이 붙는데, 

args의 length에 따라 달라짐. 

 

main은 entry point

 

terminal에서 

GradeBook skylerbang$ dotnet run skyler

으로 "skyler"라는 값을 주면 

Hello skyler가 나옴.

 

 

 

 

string args에서  list의 길이 등을 디버그로 확인 가능

 

  디버깅이 정말 중요하다고 옛날에 배운 것 같은데 여기서도 강조를 많이 해서 앞으로 많이쓰일기능인듯

 

 

build를 하면 C# sourcode가  compile 돼서 dll파일이 만들어지나? 

 dll파일이 binary code로 컴퓨터가 더 빨리 처리할 수 있나? 였던 거 같은데

 

 

Summary of 2nd video 

저 빨간 점이  break point로 지정해서 debug 할 때 저기서 멈출 수 있음. 


3번 쨰 강의는  Learning the C# Syntax 

Basic syntax를 배우는 강의였다.

 

일단 목표는 밑에 예제를 주고  푸는 방식,

 

using System;
using System.Collections.Generic;

namespace GradeBook
{
    class Program
    {
        static void Main(string[] args)
        {

            double avg_grades;
            double[] numbers = new[] { 1.1, 2.2, 3.3, 4.4 };

            var results = 0.0;
            foreach (double number in numbers)
            {
                results += number;
            }
            Console.WriteLine(results);
            /*
            result += number[1];  // result = result + number[1]
            result += number[2]; // result = result + number[2]

            */

            var grades = new List<double>() { 1.1, 2.2, 3.3, 4.4 };
            grades.Add(56.1);
            // list and array very similary but list let me add thingy more free 


            var results2 = 0.0;
            foreach (double number in grades)
            {
                results2 += number;
            }
            float i = grades.Count;
            Console.WriteLine(i);

            avg_grades = results2 / grades.Count;
            Console.WriteLine(results2);


            Console.WriteLine($"The average grade is {avg_grades:N1} !");




            /*
            result += number[1];  // result = result + number[1]
            result += number[2]; // result = result + number[2]

            */






            if (args.Length > 0)   // if statement 
            {

                Console.WriteLine($"Hello ,{args[0]} !");   // some staement need ; some are not : end of the statement
            }
            else
            {
                Console.WriteLine("Hello stranger!");
            }


        }
    }
}

 

1. variables 

int a  // integer 
float b  // floating number 
double c // double number  => 1.11
var d  //  computer will automatcially find out 

2.  arry 

Arry   만들고 new 로 initating해줘야된다 ? 

double[] numbers = new[] { 1.1, 2.2, 3.3, 4.4 };

3. list

using System.Collections.Generic; 이게 있어야하는데

저걸 그냥 복붙해도되고

list 처음 쓰고 클릭해서 보여지는 항목에서 추가해도됌


using System.Collections.Generic; 
var grades = new List<double>() { 1.1, 2.2, 3.3, 4.4 };

 

 

4. foreach

  var results2 = 0.0;
            foreach (double number in grades)
            {
                results2 += number;  // result2 = result2 + number;
            }

5. .count 

 

listname. count 로 리스트length를 구할수잇다. 


avg_grades = results2 / grades.Count;

summary of video 3 


Lecture 4 Working with classes and objects

 

Object-oriented programming  에관련한 너무많은것들이 있어서 나도 확실히 100% 이해는 못한것같다 그래도 

중요하건 밑에 필기를해놨고  여러번 더 봐야 정리가될것같다.

 

how do you knw when to make new class ?  => when you see your code if it is too complicated  to read  -> make a new class

 

Class =   1. state 

             2. behavior 

 

public : access modifier, code outside of this class can access this 

                 you can add it on class/ field 

private: only inside this class definition. 

 

Field declaration; looks very much as a variable declaration 

 

this. operator 

 

static ; instance member  , 

 

 

3번쨰 강의에서 내준 예제를 가지고 4번째 강의도 이어졌는데, 

 

처음에는 Program.cs에 하드 코딩으로 하나씩 list도 일일일 add하면서 기본적인 툴로 시작을해서

 

Book.cs 에 methode로 집어넣어서 마지막에는 prgrram.cs가 밑에 처럼 간단하게 보이도록 :

using System;
using System.Collections.Generic;

namespace GradeBook
{
    class Program
    {
        static void Main(string[] args)
        {
            /*var p = new Program();
            Program.Main(args);*/  //infinite loop

            var book = new Book("Skyler's Grade book");
            book.AddGrade(89.1);
            book.AddGrade(90.5);
            book.AddGrade(77.5);
            book.ShowStatistics();
        }
    }
}

 

여기에는  점수를 추가하면 리스트에 추가가되는 AddGrade랑 

평균, 최대값,최소값을 알려주는  ShowStatistics가 있다. 

Book.cs : 

using System.Collections.Generic;
using System;

namespace GradeBook
{

    class Book
    {

        public Book(string name)  //should have same name as the class and no void
        {
            grades = new List<double>();
            this.name = name; // implicit variable, refer to the object currently operate on 
        }

        public void AddGrade(double grade)
        {
            //List<double> grades;  this is only the local variable  so it should be out side 
            grades.Add(grade);

        }

        public void ShowStatistics()
        {
            var result = 0.0;
            var highGrade = double.MinValue;
            var lowGrade = double.MaxValue;

            foreach (var number in grades)
            {

                highGrade = Math.Max(number, highGrade);
                lowGrade = Math.Min(number, lowGrade);
                result += number;

            }
            result /= grades.Count;
            Console.WriteLine($"The average grade is {result:N1}");
            Console.WriteLine($"The lowest grade is {lowGrade:N1}");
            Console.WriteLine($"The highest grade is {highGrade:N1}");
        }

        private List<double> grades;//cant use var , using System.Collections.Generic;
        private string name;
    }

}

Summary Screenshot 안찍어 귀찮아서  - 

반응형

댓글()