Advertisement
fcamuso

Const, enum e operatori bitwise - 1

Jan 21st, 2021
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Const_Enum
  4. {
  5.  
  6.   class MyClass
  7.   {
  8.     public const double PiGreco = 3.14;
  9.     public static readonly string VersioneApp;
  10.     public static readonly bool SecurityFlag;
  11.  
  12.     static MyClass() { VersioneApp = "4.1"; SecurityFlag = true; }
  13.   }
  14.  
  15.   enum Giorno { Lun=1, Mar, Mer, Gio, Ven, Sab, Dom };                      
  16.  
  17.   class Program
  18.   {
  19.     static void M1(Giorno g) { }
  20.  
  21.     static Giorno G(int giorno)
  22.     {
  23.       if (Enum.IsDefined(typeof(Giorno), giorno))
  24.         return (Giorno)giorno;
  25.       else
  26.         throw new InvalidCastException($"Il valore {giorno} non ha corrispondenze con la enum Giorno");
  27.     }
  28.  
  29.     static void Main(string[] args)
  30.     {
  31.       Giorno mioCompleanno2021 = Giorno.Sab;
  32.       Console.WriteLine(mioCompleanno2021);
  33.  
  34.       if (mioCompleanno2021 != Giorno.Dom)
  35.         Console.WriteLine("Quest'anno il tuo compleanno non si sovrapporrà con la Pasqua");
  36.  
  37.       int n = (int)Giorno.Gio;
  38.       Giorno g1 = (Giorno)6; //sab
  39.  
  40.       g1 = (Giorno)20;
  41.       Console.WriteLine(g1);
  42.  
  43.       g1 = G(20);
  44.     }
  45.  
  46.   }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement