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

설정

트랙백

댓글

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.GetCount() + "");

    }

}

 

class Adventurer

{

    private string job;

    private int mp;

 

    // 外部からアクセスできないスタティックな変数を定義する

public static int count=0;

 

    public Adventurer(string job, int mp)

    {

        this.job = job;

        this.mp = mp;

        count++;

    }

 

    public void Attack()

    {

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

        mp -= 5;

    }

 

    public int GetMP()

    {

        return mp;

    }

 

    // 者のを返すstaticなメソッドを追加する

    public static int GetCount()

    {

        return count;

    }

 

}

///////////

/////

 

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

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.GetCount() + "種類です");

    }

}

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

public class Item

{

    private int price;

    private int quantity;

    private static int count = 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;

    }

 

    public static int GetCount()

    {

        return count;

    }

}

/////////

 

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

////

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

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.GetCount() + "種類です");

    }

}

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

public class Item

{

    private int price;

    private int quantity;

    private static int count = 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;

    }

 

    public static int GetCount()

    {

        return count;

    }

}

/////////

728x90

설정

트랙백

댓글

728x90
SMALL

// アクセス修飾子を省略しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var player = new Player("勇者");

        player.Walk();

 

        Console.WriteLine(player.name);

    }

}

 

public class Player

{

    public string name;

    // 필드의 억세스 수식자를 생략하면 private가 된다.

//string name;

 

    public Player(string name)

    {

        this.name = name;

    }

 

    public void Walk()

    {

        Console.WriteLine (name + "は荒野をいていた");

    }

    // 메소드에서 억세스 수식자를 생략하면 private가 된다.

}

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

// 필드, 콘스트럭터, 메소드에서 억세스 수식자를 생략하면 다 private가 된다.

// 인터널 억세스 수식자

// 그 안에서 사용할 수 있는 수식자

// 개발할 때 사용한다.

 

//

// staticを理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120, 15); //오브젝트 작성

        //카운트가 0에서 1이 된다.

        var total = apple.GetTotalPrice();

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

        var orange = new Item(85, 32); // 두 번째 오브젝트 작성

        //카운트가 1에서 2로 변환

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

        Console.WriteLine("商品は" + Item.GetCount() + "種類です。");

       

       

       

    }

}

 

public class Item

{

    private int price;

    private int quantity;

    public static int count=0;

    //static이라고 하면 실행이 가능하다. 불러올 수 있네

    //static 앞에 클래스의 종류 private public을 입력

   

    public Item(int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        count++;

    }

 

    public int GetTotalPrice()

    {

        return price * quantity;

    }

    public static int GetCount()

    {

        return count;

    }

   

}

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

static을 이해하자

////

728x90

설정

트랙백

댓글

728x90
SMALL

// RPGの冒者にMPを設定しよう

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());

        }

    }

}

 

class Adventurer

{

    private string job;

    private int mp;

 

    public Adventurer(string job, int mp)

    {

        this.job = job;

        this.mp = mp;

    }

 

    public void Attack()

    {

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

        mp -= 5;

    }

 

    // 現在のMPの値を返すGetMP()メソッドを装する

    public int GetMP()

    {

        return mp;

    }

   

   

 

}

//////////

///// 남은 MP 출력하기

 

////

// アクセス修飾子を理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

var player = new Player("yousha");

player.Walk();

 

 

 

    }

}

public class Player

{

    private string name;

    public Player(string name)

    {

        this.name = name;

    }

    public void Walk()

    {

        Console.WriteLine(name + "は荒野をいていた");

    }

    // public은 어디서나 억세스가 가능하다.

   

}

 

///////////

///

// アクセス修飾子を理解しよう

using System;

 

public class Lesson07

{

    public static void Main()

    {

var player = new Player("yousha");

player.Walk();

 

Console.WriteLine(player.name);

// 에러가 된다.

 

    }

}

public class Player

{

    //private string name; //여기가 private라서 안됨

    public string name;

    public Player(string name)

    {

        this.name = name;

    }

    public void Walk()

    {

        Console.WriteLine(name + "は荒野をいていた");

    }

    // public은 어디서나 억세스가 가능하다.

   

}

/////

////

728x90

설정

트랙백

댓글

728x90
SMALL

//// 사과의 금액 구하기

////////

///

// り値のあるメソッドを作ろう

using System;

 

public class Lesson07

{

    public static void Main()

    {

        var apple = new Item(120,15);

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

       

       

    }

}

public class Item

{

    private int price;

    private int quantity;

    public Item(int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        

    }

    public int GetTotalPrice()

    {

        return price * quantity;

    }

   

}

////

사과 금액은 120엔 * 15개 = 1800엔으로 출력된다.

/////

 

//////////

// り値のあるメソッドを作ろう

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() + "円です。");

       

    }

}

public class Item

{

    private int price;

    private int quantity;

    public Item(int price, int quantity)

    {

        this.price = price;

        this.quantity = quantity;

        

    }

    public int GetTotalPrice()

    {

        return price * quantity;

    }

   

}

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

////

인수와 戻り値

728x90

설정

트랙백

댓글

728x90
SMALL

// RPGの冒者クラスを作ろう

 

using System;

 

public class Practice

{

    public static void Main()

    {

        var adventurer = new Adventurer("");

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

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

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

 

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

 

        foreach (Adventurer player in party)

        {

            player.Attack();

        }

    }

}

 

///

 

모험자, 위자드, 크루세이더, 프리스트 출력

 

///

// Adventurerクラスを定義する

public class Adventurer

{

    private string name;

    public Adventurer(string name)

    {

        this.name = name;

    }

 

    public void Attack()

    {

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

       

    }

}

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

////

728x90

설정

트랙백

댓글