Advertisement
Guest User

Untitled

a guest
Oct 30th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. public class Account
  2. {
  3.     public string UserName { get; private set; }
  4.     public string Password { get; private set; }
  5.  
  6.     public Account(string UserName, string Password)
  7.     {
  8.         // check to see if the userName or password contain a space. If so, it is an error as they
  9.         // are not allowed to have spaces.
  10.         if ( UserName.Contains(" ") || UserName.Contains(" ") ){
  11.             throw new Exception("You are not allowed to have spaces in the user name or password.");
  12.         }
  13.        
  14.         // You already passed the validation -- no need for the else statement since this will only be run
  15.         // if no error is thrown :)
  16.         this.UserName = UserName;
  17.         this.Password = Password;
  18.     }
  19. }
  20.  
  21. // main method in some other class
  22. public static Main(){
  23.     try{
  24.         Account account = new Account ("someUserName", "somePassword");
  25.  
  26.         // instead of writing it out to the console, you would just open the
  27.         // filestream and shove it in there.
  28.         Console.Writeln("my user name : " + account.UserName);
  29.         Console.Writeln("my password  : " + account.Password);
  30.     }
  31.     catch(Exception e){
  32.         Console.Writeln("An error occurred. The information is as follows : ");
  33.         Console.Writeln("\tInnerException : " + e.InnerException);
  34.         Console.Writeln("\tMessage : " + e.Message);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement