Advertisement
stefan1919

Structure Conditional set

Oct 31st, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ModuleThreeAssignment
  8. {
  9.     class Program
  10.     {
  11.         enum Days { Monday, Thursday, Wednesday, Thuesday, Friday, Saturday, Sunday };
  12.         public struct Team
  13.         {
  14.             private string name;
  15.             private int points;
  16.             public int position { get; set; }
  17.     //We create a public Name, where we can set the values by using the private string name
  18.             public string Name
  19.             {
  20.                 get { return name; }
  21.                 set { name = value; }
  22.             }
  23.     //This is an example of conditional set;
  24.             public int Points
  25.             {
  26.                 get { return points;}
  27.                 set
  28.                 {
  29.                     if (value < 10)
  30.                     {
  31.                         points = 10;
  32.                     }
  33.                     if (value > 10)
  34.                     {
  35.                         points = value;
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.         static void Main(string[] args)
  41.         {
  42.             Team team1 = new Team();
  43.             team1.Name = "Marek";
  44.             team1.Points = 9;
  45.             team1.position = 1;
  46.             Console.WriteLine(team1.Points);
  47.             //output: 10
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement