Assign value static member - CSharp Custom Type

CSharp examples for Custom Type:static

Description

Assign value static member

Demo Code

using static System.Console;
using System;/*from  w  ww  .j a v a2 s.  c om*/
using System.Collections.Generic;
class Program
{
   static void Main(string[] args)
   {
      BankAccount.InterestRate = 0.012M;
      var ba1 = new BankAccount();
      ba1.AccountName = "Mrs. Jones";
      ba1.Balance = 2400;
      WriteLine($"{ba1.AccountName} earned {ba1.Balance * BankAccount.InterestRate:C} interest.");
      var ba2 = new BankAccount();
      ba2.AccountName = "Ms. Gerrier";
      ba2.Balance = 98;
      WriteLine($"{ba2.AccountName} earned {ba2.Balance * BankAccount.InterestRate:C} interest.");
   }
}
public class BankAccount
{
   public string AccountName;
   public decimal Balance;
   public static decimal InterestRate;
}

Result


Related Tutorials