「C#」同じメソッドをオーバーロードするサンプル

2021年2月14日

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
namespace ProjectKm
{
class TestInfo
{
//メソッドtestFuncA
public string testFuncA(int x)
{
return x ;
}
//メソッドtestFuncA
public string testFuncA(int x, string y)
{
return x + y;
}
}
class CftDemo
{
static void Main()
{
TestInfo cftA = new TestInfo();
string resA = cftA.testFuncA(456);
Console.WriteLine(resA);
string resB = cftA.testFuncA(123, "test33");
Console.WriteLine(resB);
}
}
}
using System; namespace ProjectKm { class TestInfo { //メソッドtestFuncA public string testFuncA(int x) { return x ; } //メソッドtestFuncA public string testFuncA(int x, string y) { return x + y; } } class CftDemo { static void Main() { TestInfo cftA = new TestInfo(); string resA = cftA.testFuncA(456); Console.WriteLine(resA); string resB = cftA.testFuncA(123, "test33"); Console.WriteLine(resB); } } }
using System;

namespace ProjectKm
{
    class TestInfo
    {
        //メソッドtestFuncA
        public string testFuncA(int x)
        {
            return x ;
        }
        //メソッドtestFuncA
        public string testFuncA(int x, string y)
        {
            return x + y;
        }
    }
    class CftDemo
    {
        static void Main()
        {
            TestInfo cftA = new TestInfo();

            string resA = cftA.testFuncA(456);
            Console.WriteLine(resA); 

            string resB = cftA.testFuncA(123, "test33");
            Console.WriteLine(resB); 
        }
    }
}

 

C#

Posted by arkgame