728x90
SMALL

////

// 長引

using System;

 

public class Lesson06

{

    public static void Main()

    {

// 얼마나 히키수가 들어가는 지 모를때

Introduce("霧島");

Introduce("勇者","","魔法使い");

//長引 params를 사용한다.

    }

   

    public static void Introduce(params string[] people)

    {

        foreach(string name in people)

        {

            Console.WriteLine("私は" + name + "です");

        }

    }

   

}

///////

私は霧島です
私は勇者です
私は戦士です
私は魔法使いです

///

// 長引

using System;

 

public class Program

{

    public static void Main()

    {

        Introduce("スライム", "ドラゴン", "魔王");

    }

 

    public static void Introduce(params string[] enemies)

    {

        foreach (var enemy in enemies)

        {

            Console.WriteLine("士は" + enemy + "った");

        }

    }

}

//////////

//

戦士はスライムと戦った
戦士はドラゴンと戦った
戦士は魔王と戦った

728x90

설정

트랙백

댓글

728x90
SMALL

// 名前付き引を理解しよう

using System;

 

public class Lesson06

{

    public static void Main()

    {

 

SayHello(target: "네코센세");

SayHello(greeting:"おはようございます。");

// 생략 시킬 수도 있다.

    }

   

    public static void SayHello(string greeting = "Hello", string target = "world")

    {

       

        Console.WriteLine(greeting + " " + target);

    }

}

///////

///

///

// 名前付き引を理解しよう

using System;

 

public class Program

{

    public static void Main()

    {

        SayHello(target: "paiza");

    }

 

    public static void SayHello(string greeting = "Hello", string target = "world")

    {

        Console.WriteLine(greeting + " " + target);

    }

}

///

///

///

///

 

728x90

설정

트랙백

댓글

728x90
SMALL

//이름을 붙인 引数

//引数를 생략하고 싶을 때 붙이는 디폴트치

//

// 名前付き引を理解しよう

using System;

 

public class Lesson06

{

    public static void Main()

    {

SayHello(); //hello world가 대입된다.

SayHello("こんにちは","皆さん"); // 디폴트치 대신에 입력한 것이 들어간다.

//곤니치와 미나상

    }

   

    public static void SayHello(string greeting = "Hello", string target = "world")

    {

       

        Console.WriteLine(greeting + " " + target);

    }

}

 

// 名前付き引を理解しよう

using System;

 

public class Lesson06

{

    public static void Main()

    {

SayHello(); //hello world가 대입된다.

SayHello("こんにちは","皆さん"); // 디폴트치 대신에 입력한 것이 들어간다.

SayHello("Good morning!"); // Good morning world가 출력된다.

// 이 경우는 두 번째 변수가 생략되어 world가나온다

 

 

    }

   

    public static void SayHello(string greeting = "Hello", string target = "world")

    {

       

        Console.WriteLine(greeting + " " + target);

    }

   

   

}

///

///

// 名前付き引を理解しよう

using System;

 

public class Lesson06

{

    public static void Main()

    {

SayHello(); //hello world가 대입된다.

SayHello("こんにちは","皆さん"); // 디폴트치 대신에 입력한 것이 들어간다.

SayHello("Good morning!"); // Good morning world가 출력된다.

// 이 경우는 두 번째 변수가 생략되어 world가나온다

SayHello(greeting: "こんにちは", target: "皆さん");

SayHello(target: "ネコ先生",greeting:"おはようございます。");

// 순번을 바꾸는 것이 가능하다.

 

    }

   

    public static void SayHello(string greeting = "Hello", string target = "world")

    {

       

        Console.WriteLine(greeting + " " + target);

    }

   

   

}

///

//////////

728x90

설정

트랙백

댓글

728x90
SMALL

// 디폴트

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

// のデフォルト値

using System;

 

public class Lesson06

{

    public static void Main()

    {

    Introduce("勇者");

    }

   

    public static void Introduce(string name)

    {

        Console.WriteLine("私は" + name + "です。");

    }

   

}

////

//私は勇者です。

 

//

//

// のデフォルト値

using System;

 

public class Lesson06

{

    public static void Main()

    {

    Introduce("勇者");

    Introduce();

    }

   

    public static void Introduce(string name = "村人")

    {

        Console.WriteLine("私は" + name + "です。");

    }

   

}

//Introduce에서

// 디폴트치를 지정할 수 있다.

// 私は勇者です。
// 私は村人です

//

//

// のデフォルト値

using System;

 

public class Program

{

    public static void Main()

    {

SayHello("Hello");

    }

 

    public static void SayHello(string greeting, string target = "paiza")

    {

        Console.WriteLine(greeting + " " + target);

    }

}

//////

//

728x90

설정

트랙백

댓글

728x90
SMALL

//RPGの攻ンを作ろう

using System;

 

public class Program

{

    public static void Main()

    {

        string[] players = { "勇者", "", "魔法使い" };

        var rand = new Random();

        int enemyHp = int.Parse(Console.ReadLine());

 

        foreach (var player in players)

        {

            var hit = rand.Next(1, 4) * 10;

            Console.WriteLine(player + "はスライムを攻した");

            // 下記にコドを追加する

            enemyHp = enemyHp-hit;

            Console.WriteLine("敵のHP" + enemyHp + "です");

        }

    }

 

    public static int Attack(int enemyHp, int hit)

    {

        enemyHp -= hit;

        return enemyHp;

    }

}

 

//

///

 

// RPGの攻ンを作ろう

using System;

 

public class Lesson06

{

    public static void Main()

    {

 

Console.WriteLine("Hello World");

// 변수의 스코프

var num = 0;

if (num == 0)

{

    var message = "paiza";

    Console.WriteLine(message + " " + num);

   

}

// 블록 밖에서는 사용 불가능

// Console.WriteLine(message + " " + num);//error

 

    }

   

   /* public static ()

    {

       

    } */

   

}

/////

///

// RPGの攻ンを作ろう

using System;

 

public class Lesson06

{

    public static void Main()

    {

Console.WriteLine("Hello World");

// 변수의 스코프

var num = 0;

if (num == 0)

{

    var message = "paiza";

    Console.WriteLine(message + " " + num);

   

}

// 블록 밖에서는 사용 불가능

// Console.WriteLine(message + " " + num);//error

//message가 없음

 

for(var i = 1; i<5;i++)

{

    var message ="C#";

    Console.WriteLine(message + " " + i);

}

 

// Console.WriteLine(message);

//에러가 뜬다.

    }

 

}

/////////

// 블록 안에 설치된 변수만 실행이 된다.

// 변수의 스코프를 인식할 필요가 있다.

728x90

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

C# paiza 54 - 이름을 붙인 引数  (0) 2020.05.16
C# paiza 53 - 인수의 디폴트치1  (0) 2020.05.16
C# paiza 51 - RPG의 공격 Scene1  (0) 2020.05.16
C# paiza 50 - 스코프  (0) 2020.05.16
C# paiza 49 - 곱셉 메소드 만들기  (0) 2020.05.16

설정

트랙백

댓글

728x90
SMALL

// 間違い探し

using System;

 

public class Program

{

    public static void Main()

    {

       

        SayHello();

    }

 

    public static void SayHello()

    {

        string message = "Hello";

        message += " ";

        message += "paiza";

        Console.WriteLine(message);

    }

}

//출력: paiza

/////

////

 

//

// RPGの攻ンを作ろう

using System;

 

public class Lesson06

{

    public static void Main()

    {

string[] enemies = {"スライム", "モンスタ", "ドラゴン"};

foreach(var enemy in enemies)

{

    //Console.WriteLine("勇者は" + enemy + "を攻した");

    Attack(enemy);

   

   

}

    }

 

    public static void Attack(string target)

    {

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

       

    }

}

 

///

///

 

// RPGの攻ンを作ろう

using System;

 

public class Lesson06

{

    public static void Main()

    {

string[] enemies = {"スライム", "モンスタ", "ドラゴン"};

foreach(var enemy in enemies)

{

    var rand = new Random();

     var num = rand.Next(10);

    Attack(enemy,num);

   

   

}

 

    }

 

    public static void Attack(string target, int hit)

    {

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

        if(hit < 5)

        {

            Console.WriteLine(target + "" + hit + "のダメジをえた");

        }

        else

        {

            Console.WriteLine("クリティカルヒット!" + target + "に100のダメジをえた");

        }

}

}

////

/////

////

///

 

728x90

설정

트랙백

댓글

728x90
SMALL

/// scope

//////

// スコプを理解しよう

using System;

 

public class Lesson06

{

    public static void Main()

    {

        int a = 10;

        int b = 20;

        int num = Sum(a,b);

        Console.WriteLine(num);

 

       

    }

          public static int Sum(int x, int y)

        {

            return x + y;

           

   

        }

}

//////

///

 

// スコプを理解しよう

using System;

 

public class Lesson06

{

    public static void Main()

    {

        int a = 10;

        int b = 20;

        int num = Sum(a,b);

        Console.WriteLine(num);

       

    }

          public static int Sum(int x, int y)

        {

            int a = 3;

            Console.WriteLine("hello" + a);

            // 여기에 a변수와 위의 a변수는 노상관

            // scopeが別れている

            return x + y;

   

        }

}

///////

///a가 두 군에서 나오는데 메소드안에 있는 거는 다르다. 구분된다.

////

728x90

설정

트랙백

댓글

728x90
SMALL

////곱셈

/////////

// 掛け算メソッドを呼び出してみよう

using System;

 

public class Program

{

    public static void Main()

    {

        // この下にメソッド呼び出しを記述する

        Multiply(3,4);

    }

 

    public static void Multiply(int x, int y)

    {

        Console.WriteLine(x * y);

    }

}

/////

 

///

// 九九の表を作成してみよう

using System;

 

public class Program

{

    public static void Main()

    {

        for(int i = 1; i < 10; i++)

        {

            for(int j = 1; j < 10; j++)

            {

                // ここでメソッドを呼び出す

    Multiply(i,j);

                if(j != 9){

                    Console.Write(", ");

                }

            }

            Console.WriteLine();

        }

    }

 

    public static void Multiply(int x, int y)

    {

        Console.Write(x * y);

    }

}

////

/////

728x90

설정

트랙백

댓글