人类的世界有许多的工厂,
将原料送入後就会变成商品,
C#的世界里也是,
方法就像一间间的工厂一样,
一发包就能得到想要的东西
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//我们来呼叫方法并赋值给变数
string animal = GetChicken();
Console.WriteLine(animal);
Console.ReadKey();
}
//宣告字串方法
static string GetChicken()
{
return "孤独一只鸡";
}
}
}
结果:
孤独一只鸡
使用static关键字时,表示他是静态的,所以不需要去new他
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//来取得过去的一个时间吧
string MtDate = GetDate(1995, 4, 9);
Console.WriteLine(MtDate);
//来取得今日的时间吧
MtDate = GetDate(2021, 9, 17);
Console.WriteLine(MtDate);
Console.ReadKey();
}
//宣告一个组合日期的方法
static string GetDate(int y,int M,int d)
{
//因为值传进来是正数所以需要转成字串
string Date_y = Convert.ToString(y);//第一种转型方式Convert.To...
string Date_M = M.ToString();//第二种转型方式 参数.ToString()
string Date_d = d.ToString();
//组合回传字串,用return回传
return Date_y + "年 " + Date_M + "月 " + Date_d + "日";
}
}
}
结果:
1995年 4月 9日
2021年 9月 17日
本文同步刊载於我的部落格:在 ubuntu 21.04 上轻松安装呒虾米 来试试在 ubuntu 2...
参赛将近半个月,终於完成了我认为贴近infra的部分,这也是为什麽要做个小结的原因,大部分企业在使用...
Reducer Reducer 这个概念, 来源於 React 的延伸套件 Redux, 其核心由 ...
简易呼叫(Simple Call) 当我们直接执行函式时,就是所谓的简易呼叫(Simple Call...