using System;
using System.Linq;
namespace SampleNamespace;
public class BankAccount
{
public string Number { get; }
public string Owner { get; set; }
public decimal Balance { get; }
public void MakeDeposit(decimal amount, DateTime date, string note)
{
}
public void MakeWithdrawal(decimal amount, DateTime date, string note)
{
}
}
class
跟 一個 method
先來印個 Console.WriteLine
namespace WebApplication2;
public class BankAccount
{
public string Number { get; }
public string Owner { get; set; }
public decimal Balance { get; }
private static int _sAccountNumberSeed = 1234567890;
public BankAccount(string name, decimal initialBalance)
{
Owner = name;
Balance = initialBalance;
Number = _sAccountNumberSeed.ToString();
}
public void MakeDeposit(decimal amount, DateTime date, string note)
{
}
public void MakeWithdrawal(decimal amount, DateTime date, string note)
{
}
}
Program.cs file
using WebApplication2;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
object var;
var account = new BankAccount("Debby", 1000);
app.MapGet("/", () =>
Console.WriteLine($"Account {account.Number} was created for {account.Owner} with {account.Balance} initial balance.")
);
app.Run();
就可以打開 terminal 裡面看到:Account 1234567890 was created for Debby with 1000 initial balance.
💡 特別注意:
C# 每行程式需要用 ; 結尾假設沒有用 using System 的寫法,就會變成:
—> System.Console.WriteLine(參數或內容);
在 rider 上可以看到被使用到的變數都會有 usage 的提醒,你可以點選 2usages 查看變數在哪邊被用到,或者也可以直接點選變數名稱後按下 F12 就可以找到了!
假設之後有要修改名稱的話,這邊提供一下小快速鍵,我們可以在變數名稱上按 F2做全域的改名,這樣就不怕被用到得地方忘記改啦!
參考文章: