「C#」静的メソッド(static method)を使うサンプル

2020年11月1日

構文
public static 戻り値の型 methodname(){
some code
}
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
namespace ProjectAbc
{
class StudyDemo
{
static void Main()
{
CftDemo.FuncA();
CftDemo tt = new CftDemo();
tt.FuncB();
}
}
public class CftDemo
{
public static void FuncA()
{
Console.WriteLine("this is a message");
}
public void FuncB()
{
Console.WriteLine("today345");
}
}
}
using System; namespace ProjectAbc { class StudyDemo { static void Main() { CftDemo.FuncA(); CftDemo tt = new CftDemo(); tt.FuncB(); } } public class CftDemo { public static void FuncA() { Console.WriteLine("this is a message"); } public void FuncB() { Console.WriteLine("today345"); } } }
using System;

namespace ProjectAbc
{
      class StudyDemo
      {
            static void Main()
            {
                  CftDemo.FuncA(); 

                  CftDemo tt = new CftDemo();
                  tt.FuncB(); 
            }
      }
      public class CftDemo
      {
            public static void FuncA()
            {
                  Console.WriteLine("this is a message");
            }
            public void FuncB()
            {
                  Console.WriteLine("today345");
            }
      }
}

結果
this is a message
today345

C#

Posted by arkgame