Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace demo
- {
- class Freight
- {
- //име и тегло
- //валидации:
- //1. името не трябва да е празно -> Name cannot be empty
- //2. теглото не трябава да е < 0 -> Weight cannot be negative
- private string name;
- private int weight;
- //конструктор
- public Freight(string name, int weight)
- {
- this.Name = name;
- this.Weight = weight;
- }
- //get и set за полето name
- public string Name
- {
- get { return this.name; }
- set
- {
- //валидация на стойността
- if(string.IsNullOrEmpty(value))
- {
- Console.WriteLine("Name cannot be empty");
- }
- else
- {
- this.name = value;
- }
- }
- }
- //get и set за полето weight
- public int Weight
- {
- get { return this.weight; }
- set
- {
- if (value < 0)
- {
- Console.WriteLine("Weight cannot be negative");
- }
- else
- {
- this.weight = value;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment