Created
June 29, 2019 11:10
-
-
Save jindeveloper/2fb1cb6b307835ea24ea03bfbdde0d4c to your computer and use it in GitHub Desktop.
C# struct sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
public interface IEmployee | |
{ | |
void DefaultRecords(); | |
} | |
public enum Benefit | |
{ | |
FullBenefit = 0, | |
HalfBenefit = 1, | |
None = 2 | |
} | |
public struct Employee : IEmployee | |
{ | |
#region fields | |
private int _employeeId; | |
private string _mobileNumber; | |
private string _firstName; | |
private string _lastName; | |
#endregion | |
#region constructor | |
public Employee(string firstName, string lastName, string mobileNumber) | |
{ | |
this._employeeId = 0; | |
this._firstName = firstName; | |
this._lastName = lastName; | |
this._mobileNumber = mobileNumber; | |
this.EmployeeBenefit = Benefit.FullBenefit; | |
} | |
#endregion | |
#region properties | |
public int EmployeeId { get { return _employeeId; } set { this._employeeId = value; } } | |
public Benefit EmployeeBenefit { get; set; } | |
public string MobileNumber { get { return this._mobileNumber; } } | |
#endregion | |
#region methods | |
public bool HasMobileNumber() | |
{ | |
return !string.IsNullOrEmpty(this._mobileNumber); | |
} | |
//Having a static method | |
public static void IsEmployeeHappy() | |
{ | |
Console.WriteLine("I'm only happy when you are happy"); | |
} | |
//Implemented from an Interface | |
public void DefaultRecords() | |
{ | |
Console.WriteLine("No records found"); | |
} | |
#endregion | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var emp = new Employee("Jin Vincent", "Necesario", ""); | |
Console.WriteLine($"Has Mobile Number: {emp.HasMobileNumber()}"); | |
Employee.IsEmployeeHappy(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment