标签:star cube stat orm write goto rds loop color
static void LocalMethod() { Cube(100); void Cube(int x) => Console.WriteLine($"The cube of {x} is {x * x * x}"); } static void GoToDemo() { int i = 1; startLoop: if(i<=5) { Console.WriteLine(i); i++; goto startLoop; } }
deconstructor
class Rectangle { public readonly float Width, Height; public Rectangle(float width,float height) { Width = width; Height = height; } public void Deconstruct(out float width,out float height) { width = Width; height = Height; } } static void Main(string[] args) { var rect = new Rectangle(3, 4); (float width, float height) = rect; Console.WriteLine($"width:{width},height:{height}"); Console.ReadLine(); }
static void Main(string[] args) { var rect = new Rectangle(3, 4); var (width, height) = rect; Console.WriteLine($"width:{width},height:{height}"); Console.ReadLine(); }
static void Main(string[] args) { var rect = new Rectangle(3, 4); (var width,var height) = rect; Console.WriteLine($"width:{width},height:{height}"); Console.ReadLine(); }
class Product { decimal currentPrice, sharesOwned; public decimal Worth { get { return currentPrice * sharesOwned; } } public decimal Worth2 => currentPrice * sharesOwned; public decimal Worth3 { get => currentPrice * sharesOwned; set => sharesOwned = value / currentPrice; }
public decimal CurrentPrice { get; set; } = 123;
public int Maximum { get; } = 999;
}
private decimal x; public decimal X { get { return x; } private set { x = Math.Round(value, 2); } }
Indexer
class Sentence { string[] words = "The quick brown fox".Split(); public string this[int wordNum] { get { return words[wordNum]; } set { words[wordNum] = value; } } } static void Main(string[] args) { Sentence se = new Sentence(); Console.WriteLine(se[3]); se[3] = "kangaroo"; Console.WriteLine(se[3]); Console.ReadLine(); }
static class StaticClass { static StaticClass() { Console.WriteLine("This is the static constructor of the static class!"); } public static DateTime DT = DateTime.Now; }
Partial class,partial method.
partial class PaymentForm { partial void ValidatePayment(decimal amount); public void InvokePartialMethod(decimal amount) { ValidatePayment(amount); } } partial class PaymentForm { partial void ValidatePayment(decimal amount) { if(amount>100) { Console.WriteLine("Luxury"); } else { Console.WriteLine("Ok"); } } } static void Main(string[] args) { PaymentForm pf = new PaymentForm(); pf.InvokePartialMethod(10); pf.InvokePartialMethod(101); Console.ReadLine(); }
标签:star cube stat orm write goto rds loop color
原文地址:https://www.cnblogs.com/Fred1987/p/12238973.html