c# property get set
class Person
{
private string name; // field
public string Name // property
{
get { return name; } // get method
set { name = value; } // set method
}
} float amount {get; set;}
static float interest = 9.5f;
public float InitialAmount{
set{ if(value < 1000) Console.Write("Nope must be > 1000"); }
get{ return amount;}
}
public static float InterestRate
{
get {return interest;} //Read only ... no setter
}
public static float InterestRate2
{
// no external class can assign this value ... it's private
private set{interest= value;}
get{return interest;}
}
using System;
public class SaleItem
{
public string Name
{ get; set; }
public decimal Price
{ get; set; }
}
class Program
{
static void Main(string[] args)
{
var item = new SaleItem{ Name = "Shoes", Price = 19.95m };
Console.WriteLine($"{item.Name}: sells for {item.Price:C2}");
}
}
// The example displays output like the following:
// Shoes: sells for $19.95
Also in C#:
- switch case c# contains
- c# singleton
- check if current time is in the morning c#
- order by C#
- unity c# get bool from another script
- c# variable
- c# transform
- c# change material in code
- unity clamp rotation
- unity making homing missile
- c# send email
- unity how to get y value
- add variable to the beginning of a list c#
- add row count devepxress report
- gersener waves
- asp net identity add a unique fields to user
- c# repeat string x times
- unity get number of child objects
- panel drag all form c#
- native-googlesignin configuration is null!?
- percentage in c#
- c# remove last character from string
- remove from list based on condition c#
- making pong in unity