c# property get set
C#
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#:
- Title
- c# input integer
- Category
- C#
- Title
- unity ui not seen
- Category
- C#
- Title
- unity fps counter
- Category
- C#
- Title
- Net.ServicePointManager.SecurityProtocol .net framework 4
- Category
- C#
- Title
- change partial view based on select asp.net core
- Category
- C#
- Title
- unity lerp
- Category
- C#
- Title
- c# list to string
- Category
- C#
- Title
- center an image horizontally and vertically
- Category
- C#
- Title
- c# regex to find number between parenthesis
- Category
- C#
- Title
- C# Unknown column 'FundAllocation' in 'field list
- Category
- C#
- Title
- c sharp exit while loop
- Category
- C#
- Title
- unity make a int arry with preset values
- Category
- C#
- Title
- unity docs player input
- Category
- C#
- Title
- unity get max occurrence in list
- Category
- C#
- Title
- unity gameobjects with tag
- Category
- C#
- Title
- csharp datetime string format
- Category
- C#
- Title
- what is type unity
- Category
- C#
- Title
- how to locate a specific element in a list c#
- Category
- C#
- Title
- c# clear console read chache
- Category
- C#
- Title
- unity serializefield
- Category
- C#
- Title
- unity variable from another script
- Category
- C#
- Title
- unity next scene
- Category
- C#
- Title
- unity 2d Drag object
- Category
- C#
- Title
- mysql executeScalar only if successful
- Category
- C#
- Title
- C# downloadstirng download old
- Category
- C#
- Title
- instantiate object in circle
- Category
- C#
- Title
- IEnumerator
- Category
- C#
- Title
- unity 2d rotate towards direction
- Category
- C#
- Title
- loops in coding
- Category
- C#
- Title
- how to make a pause feautre in unity
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- constructor in inherited class c#
- Category
- C#
- Title
- : ? conditioanl statement c#
- Category
- C#
- Title
- generate a dropdown list from array data using razor .net mvc
- Category
- C#
- Title
- c# implement ienumerable t
- Category
- C#
- Title
- change Backcolor c#
- Category
- C#
- Title
- rotate to face direction
- Category
- C#
- Title
- c# odd even median
- Category
- C#
- Title
- c# date
- Category
- C#
- Title
- C# string is all zeros
- Category
- C#
- Title
- c# postfix increment operator overload
- Category
- C#
- Title
- how to run csharp in visual studio code
- Category
- C#
- Title
- open zip file in c#
- Category
- C#
- Title
- asp.net core redirecttoaction with parameters
- Category
- C#
- Title
- delay in unity
- Category
- C#
- Title
- bind repeater to dictionary
- Category
- C#
- Title
- system.io.directorynotfoundexception c#
- Category
- C#
- Title
- unity timer with miliseconds
- Category
- C#
- Title
- winforms timer c#
- Category
- C#
- Title
- stop ui from clipping wall
- Category
- C#
- Title
- C# webclient submit form
- Category
- C#
- Title
- vb.net tostring numeric format string
- Category
- C#
- Title
- c# size of enum
- Category
- C#
- Title
- console application in c# ms crm
- Category
- C#
- Title
- c sharp split by newline
- Category
- C#
- Title
- how to remove file changes in git
- Category
- C#
- Title
- c# integer to bit string
- Category
- C#
- Title
- Request.Form
- Category
- C#
- Title
- c# change label forecolor code
- Category
- C#
- Title
- initialize enum with another enum c#
- Category
- C#
- Title
- c# type of generic is string
- Category
- C#
- Title
- unity check tag
- Category
- C#
- Title
- c# check file exists
- Category
- C#
- Title
- c# append to file
- Category
- C#
- Title
- how to check if an integer is in array c#
- Category
- C#
- Title
- c# select first value from list
- Category
- C#
- Title
- how to pause physics in unity c#
- Category
- C#
- Title
- kill child C#
- Category
- C#
- Title
- unity movetowards 2d
- Category
- C#
- Title
- .net identity seed users and roles
- Category
- C#
- Title
- C# array to string
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- c# singleton
- Category
- C#
- Title
- uncaught syntaxerror invalid or unexpected token unity webgl
- Category
- C#
- Title
- check if string is email c#
- Category
- C#
- Title
- how to add a list to observablecollection in c#
- Category
- C#
- Title
- get first and last item list c#
- Category
- C#
- Title
- unity simple fps controller
- Category
- C#
- Title
- unity rotation
- Category
- C#
- Title
- C# save pdf stream to file
- Category
- C#
- Title
- exit game unity
- Category
- C#
- Title
- How to make a function in C#
- Category
- C#
- Title
- c# string list contains
- Category
- C#
- Title
- how to reference scripts in other scenes unity
- Category
- C#
- Title
- parsing string to int without format exception c#
- Category
- C#
- Title
- epplus excel vb.net
- Category
- C#
- Title
- c# map
- Category
- C#
- Title
- get random value from list c#
- Category
- C#
- Title
- unity indestructible
- Category
- C#
- Title
- how to get component in unity c#
- Category
- C#
- Title
- unity input get axis
- Category
- C#
- Title
- never lose focus textbox c#
- Category
- C#
- Title
- hot to move pobject unity
- Category
- C#
- Title
- no entity framework provider found for the ado.net provider with invariant name
- Category
- C#
- Title
- how to change the title of the console in c#
- Category
- C#
- Title
- unity 2d joystick controls
- Category
- C#
- Title
- c# window instantly close
- Category
- C#
- Title
- unity add component
- Category
- C#
- Title
- displayname c#
- Category
- C#
- Title
- c# xml file builder
- Category
- C#