728x90
SMALL

// 標準ライブラリを使ってみよう

using System;

using System.Collections.Generic;

 

class Lesson08

{

    public static void Main()

    {

        var team = new List<string>();

 

        // Add()

team.Add("勇者");

team.Add("");

team.Add("魔法使い");

 

 

        foreach (var member in team)

        {

             Console.WriteLine(member);

        }

 

        Console.WriteLine();

 

        // Insert()

team.Insert(2,"忍者");

 

        foreach (var member in team)

        {

             Console.WriteLine(member);

        }

 

        Console.WriteLine();

 

        // Remove()

team.Remove("");

       

        foreach (var member in team)

        {

             Console.WriteLine(member);

        }

    }

}

728x90

'프로그래밍' 카테고리의 다른 글

C# paiza 74 - 딕셔너리2  (0) 2020.05.22
C# paiza 73 - 딕셔너리(Dictionary)1  (0) 2020.05.22
C# paiza 71 - NameSpace  (0) 2020.05.19
C# paiza 70 - 오버로드2  (0) 2020.05.19
C# paiza 69 - 오버로드1  (0) 2020.05.19

설정

트랙백

댓글

728x90
SMALL

////////////

///

//Namespace

//Array 클래스, Console 클래스, Exception 클래스, Math 클래스, Random 클래스

//시스템IO 클래스

//file 클래스, FileInfo 클래스, 파일 스트림 클래스, 디렉토리 클래스, 패스 클래스

//클래스를 정리하는 것이 가능하다.

System.Console.WriteLine();

시스템은 이름공간, Console은 클래스, WriteLine은 메소드이다.

////////////

 

///

///

// 標準ライブラリを使ってみよう

using System; //이름공간 내용을 넣어서 생략 가능

//Console.WriteLine = 원래는 System.Console.WriteLine이었다.

using System.Collections.Generic;

 

class Lesson08

{

    public static void Main()

    {

        //미리 허락된 기능군

        //클래스로 구성되어 있다.

        //Namespace에석 관리된다.

        var team = new List<string>();

        team.Add("勇者");

        team.Add("");

        team.Add("魔法使い");

    foreach(var member in team)

    {

        Console.WriteLine(member);

    }

   

       

    }

}

////////////

///

// 標準ライブラリを使ってみよう

using System; //이름공간 내용을 넣어서 생략 가능

//Console.WriteLine = 원래는 System.Console.WriteLine이었다.

using System.Collections.Generic;

 

class Lesson08

{

    public static void Main()

    {

        //미리 허락된 기능군

        //클래스로 구성되어 있다.

        //Namespace에석 관리된다.

        var team = new List<string>();

        team.Add("勇者");

        team.Add("");

        team.Add("魔法使い");

    foreach(var member in team)

    {

        Console.WriteLine(member);

    }

     Console.WriteLine();

    

    team.Insert(2,"忍者");

    foreach(var member in team)

   

{

    Console.WriteLine(member);

   

}

 

Console.WriteLine();

team.Remove("");

foreach(var member in team)

{

    Console.WriteLine(member);

}

 

       

    }

}

////

728x90

설정

트랙백

댓글

728x90
SMALL

/////

// ドを理解しよう

using System;

 

class Lesson08

{

    public static void Main()

    {

        Learning();

        Learning("Ruby");

        Learning("C#", "paiza");

    }

 

    static void Learning()

    {

        Console.WriteLine("私はプログラミングを習した");

    }

 

    // 1つのLearningメソッドを定義してください

 

static void Learning(string target)

{

    Console.WriteLine("私は" + target + "習した");

}

    // 2つのLearningメソッドを定義してください

static void Learning(string target1, string target2)

{

    Console.WriteLine("私は" + target1 + "" + target2 + "習した");

   

}

 

 

}

///

 

///

/////

// ドを理解しよう

using System;

 

class Lesson08

{

    public static void Main()

    {

        Run();

        Run("箱根");

        Run("400mトラック", 25);

    }

 

    static void Run()

    {

        Console.WriteLine("私は走った");

    }

 

    // 1つのString型のRunメソッドを定義してください

 static void Run(string target)

 {

     Console.WriteLine("私は" + target + "を走った");

 }

 

    // 1つのString型と1つのint型のRunメソッドを定義してください

     static void Run(string target, int num)

 {

     Console.WriteLine("私は" + target + "" + num + "周走った");

 }

 

}

/////////

728x90

설정

트랙백

댓글

728x90
SMALL

// ドを理解しよう

using System;

 

class Lesson08

{

    public static void Main()

    {

        Attack(); //인수가 없으면 그냥

        Attack("スライム"); //인수를 넣으면 아래로

       

    }

    static void Attack()

    {

        Console.WriteLine("勇者は、敵を攻した。");

    }

   

    static void Attack(string target)

    {

        Console.WriteLine("勇者は、" + target + "を攻した。");

    }

   

}

/////////// 데이터의 오버로드

//////

 

// ドを理解しよう

using System;

 

class Lesson08

{

    public static void Main()

    {

        Attack(); //인수가 없으면 그냥

        Attack("スライム"); //인수를 넣으면 아래로

        Attack(10); //인수에 숫자를 입력

    }

    static void Attack()

    {

        Console.WriteLine("勇者は、敵を攻した。");

    }

   

    static void Attack(string target)

    {

        Console.WriteLine("勇者は、" + target + "を攻した。");

    }

    static void Attack(int number)

    {

        Console.WriteLine("勇者は、" + number + "匹現れた");

    }

   

   

}

///////

//////인수에 정수 대입

//////

 

//

///////

// ドを理解しよう

using System;

 

class Lesson08

{

    public static void Main()

    {

        Attack(); //인수가 없으면 그냥

        Attack("スライム"); //인수를 넣으면 두 번째로

        Attack(10); //인수에 숫자를 입력

        Attack("ドラゴン",3); //문자열과 숫자를 입력하면 맨 아래

       

    }

    static void Attack()

    {

        Console.WriteLine("勇者は、敵を攻した。");

    }

   

    static void Attack(string target)

    {

        Console.WriteLine("勇者は、" + target + "を攻した。");

    }

    static void Attack(int number)

    {

        Console.WriteLine("勇者は、" + number + "匹現れた");

    }

    static void Attack(string target, int number)

    {

        Console.WriteLine("勇者は、" + number + "匹の" + target + "を攻した");

    }

   

}

728x90

설정

트랙백

댓글

728x90
SMALL

// Stringクラスの持つメソッドを使ってみよう

 

using System;

 

public class Practice

{

    public static void Main()

    {

        var str = "The apple never falls far from the tree.";

 

        // それぞれのメソッドの結果を1行ずつ出力する

Console.WriteLine(str.ToUpper());

Console.WriteLine(str.Substring(4)); //0부터 시작해서 4번째 문자부터 출력

Console.WriteLine(str.IndexOf("apple"));

 

    }

}

///////////////

728x90

설정

트랙백

댓글

728x90
SMALL

// 文字列や配列もオブジェクトになっている

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var text = "Hello World";

        Console.WriteLine(text.Length);

       

        Console.WriteLine(text);

Console.WriteLine(text.ToUpper()); //대문자로 출력하기

       

       

    }

}

///문자 출력 숫자 조회

 

//

// 文字列や配列もオブジェクトになっている

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var text = "Hello World";

        Console.WriteLine(text.Length);

        Console.WriteLine(text.ToUpper());

        Console.WriteLine(text);

       

        int[] numbers = {1,2,3,4};

        foreach(var number in numbers)

        {

            Console.Write(number + " ");

           

        }

       

       

    }

}

///////

//배열의 요소 출력

//

// 文字列や配列もオブジェクトになっている

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var text = "Hello World";

        Console.WriteLine(text.Length);

        Console.WriteLine(text.ToUpper());

        Console.WriteLine(text);

       

        int[] numbers = {1,2,3,4};

        foreach(var number in numbers)

        {

            Console.Write(number + " ");

           

        }

        Console.WriteLine();

        numbers.SetValue(100, 2);

      

        foreach(var number in numbers)

        {

            Console.Write(number + " ");

           

        }

        Console.WriteLine();

        Console.WriteLine(numbers.Length);

       

    }

}

/////

//////////

//

728x90

설정

트랙백

댓글

728x90
SMALL

// アクセッサをプロパティに置き換えよう

 

using System;

 

public class Practice

{

    public static void Main()

    {

        var adventurer = new Adventurer("", 120);

        var wizard = new Adventurer("ウィザ", 549);

        var crusader = new Adventurer("クルセイダ", 50);

        var priest = new Adventurer("プリスト", 480);

 

        Adventurer[] party = {adventurer, wizard, crusader, priest};

 

        foreach (Adventurer player in party)

        {

            player.Attack();

            Console.WriteLine("MP" + player.GetMP());

        }

 

        Console.WriteLine("者の" + Adventurer.Count + "");

    }

}

 

class Adventurer

{

    private string job;

    private int mp;

 

    private static int count;

 

    public Adventurer(string job, int mp)

    {

        this.job = job;

        this.mp = mp;

        Count += 1;

    }

 

    public void Attack()

    {

        Console.WriteLine(job + "は魔王を攻した");

        mp -= 5;

    }

 

    public int GetMP()

    {

        return mp;

    }

 

 

 

    // Countプロパティに置き換える

public static int Count { get; private set; }

}

728x90

설정

트랙백

댓글

728x90
SMALL

// プロパティを理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120, 15);

        var total = apple.GetTotalPrice();

        Console.WriteLine("合計金額は" + total + "円です");

        var orange = new Item(85, 32);

        Console.WriteLine("合計金額は" + orange.GetTotalPrice() + "円です");

//item.Count =0;를 대입하면 0이 된다.

        Console.WriteLine("アイテムは" + Item.Count + "種類です");

    }

}

// 프로퍼티 요미카키 할 때 사용

public class Item

{

    private int price;

    private int quantity;

    private static int count; //C#에서는 0으로 자동으로 대입되어 있다.

    // 관례적으로 프로퍼티의 앞을 대문자로. 소문자로 해도 됨.

    public static int Count

    {

        get

        {

            return count;

        }

        set

        {

            count = value;

        }

       

    }

//카운트 프로퍼티가 됐다.

 

    public Item (int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        Count += 1;

    }

 

    public int GetTotalPrice()

    {

        return price * quantity;

    }

 

 

}

////////////

 

 

////

// プロパティを理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120, 15);

        var total = apple.GetTotalPrice();

        Console.WriteLine("合計金額は" + total + "円です");

        var orange = new Item(85, 32);

        Console.WriteLine("合計金額は" + orange.GetTotalPrice() + "円です");

//item.Count =0;를 대입하면 0이 된다.

        Console.WriteLine("アイテムは" + Item.Count + "種類です");

    }

}

// 프로퍼티 요미카키 할 때 사용

public class Item

{

    private int price;

    private int quantity;

    private static int count; //C#에서는 0으로 자동으로 대입되어 있다.

    // 관례적으로 프로퍼티의 앞을 대문자로. 소문자로 해도 됨.

    public static int Count

    {

        get

        {

            return count;

        }

        set

        {

            count = value;

        }

       

    }

//카운트 프로퍼티가 됐다.

 

    public Item (int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        Count += 1;

    }

 

    public int GetTotalPrice()

    {

        return price * quantity;

    }

 

 

}

//////////

////

//

// プロパティを理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120, 15);

        var total = apple.GetTotalPrice();

        Console.WriteLine("合計金額は" + total + "円です");

        var orange = new Item(85, 32);

        Console.WriteLine("合計金額は" + orange.GetTotalPrice() + "円です");

        Console.WriteLine("アイテムは" + Item.Count + "種類です");

    }

}

// 프로퍼티 요미카키 할 때 사용

public class Item

{

    private int price;

    private int quantity;

    // 관례적으로 프로퍼티의 앞을 대문자로. 소문자로 해도 됨.

    public static int Count { get; private set; }

//count 필드가 없어도 작동한다.

 

    public Item (int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        Count += 1;

    }

 

    public int GetTotalPrice()

    {

        return price * quantity;

    }

}

///////////

728x90

설정

트랙백

댓글