穿插算法和数据结构
var类型可以根据复制自动推断变量属性
应为get或set访问器:方法名没加括号
变量和方法(循环,递归)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassMethodExample
{
class Program
{
static void Main(string[] args)
{
Calculator AddObeject = new Calculator();//实例化add为calculator对象,声明add是Calculator类的对象
int x = AddObeject.Add(1, 2);
Console.WriteLine(x);
Calculator GetDayObject = new Calculator();//声明GetDayObject是Calculator类的对象
string day = GetDayObject.GetToday();//调用对象的方法
Console.WriteLine(day);
Calculator PrintSub = new Calculator();
PrintSub.PrintSum(3,4);
}
}
class Calculator { //创建计算类
//创建相加方法(函数),public代表可以在主函数里公开调用
public int Add(int a,int b) {
int result = a + b;
return result;
}
public string GetToday(){ //创建计算类下的gettoday方法
int DayTime=DateTime.Now.Day;
return DayTime.ToString();
}
public void PrintSum(int a,int b) {
var Sum = a + b;
Console.WriteLine(Sum);
}
}
}
标签:变量,C#,Calculator,System,int,算法,WriteLine,using,public From: https://www.cnblogs.com/houyuxuan/p/17699242.html