Click here to Skip to main content
15,887,676 members
Home / Discussions / C#
   

C#

 
GeneralRe: Understanding changes of the mouse icon Pin
Eddy Vluggen23-Sep-13 5:50
professionalEddy Vluggen23-Sep-13 5:50 
AnswerRe: Understanding changes of the mouse icon Pin
BillWoodruff23-Sep-13 4:55
professionalBillWoodruff23-Sep-13 4:55 
AnswerRe: Understanding changes of the mouse icon Pin
Pete O'Hanlon23-Sep-13 7:07
mvePete O'Hanlon23-Sep-13 7:07 
GeneralRe: Understanding changes of the mouse icon Pin
ExcellentOrg23-Sep-13 8:23
ExcellentOrg23-Sep-13 8:23 
GeneralRe: Understanding changes of the mouse icon Pin
Pete O'Hanlon23-Sep-13 8:41
mvePete O'Hanlon23-Sep-13 8:41 
GeneralRe: Understanding changes of the mouse icon Pin
ExcellentOrg25-Sep-13 20:05
ExcellentOrg25-Sep-13 20:05 
GeneralExample 5-14 - Drill 5-3 Pin
N8tiv23-Sep-13 0:51
N8tiv23-Sep-13 0:51 
GeneralRe: Example 5-14 - Drill 5-3 Pin
Pete O'Hanlon23-Sep-13 1:24
mvePete O'Hanlon23-Sep-13 1:24 
In this example, you've got some stuff wrong. For a start, why do you have a separate method to display the information from each class. You would have been better off overriding a method here. Similarly, I would look at changing the way that you gather information - the Citizen constructor violates way too many good practices. If I were writing this, I would look at something like this
C#
public class Citizen
{
  public string Ssn;
  public int Age; 
  
  public virtual void GetDetails()
  {
     SSN = GetInput("Please enter the citizen's Social Security number: ");
     Age = GetAge();
  }

  public virtual void DisplayInfo()
  {
    Console.WriteLine("Citizen's Information:");
    Console.WriteLine("SSN: {0}", Ssn);
    Console.WriteLine("Age: {0}{1}", Age, Environment.NewLine);
  }

  protected string GetInput(string message)
  {
    Console.WriteLine(message);
    return Console.ReadLine();
  }

  private void GetAge()
  {
     bool success = false;
     int age;
     while (!success)
     {
       string tempAge = GetInput("Please enter the citizen's age: ");
       bool success = int.TryParse(tempAge, age);
       if (!success)
       {
         Console.WriteLine("Unfortunately, you did not enter a valid integer (or whatever message you like here");
       }
     }
  }
}

public class Employee : Citizen
{
  public string Name;
  public string Id;

  public override void GetDetails()
  {
    base.GetDetails();

    Name = GetInput("Please enter the employee's name:");
    Id = GetInput("Please enter the employee's id:");
  }

  public override void DisplayInfo()
  {
    base.DisplayInfo();
    Console.WriteLine("Employee's name: {0}", Name);
    WriteLine("Employee's id: {0}", Id);
  }
}
As you can see, the classes are now largely self contained. We have some common functionality handled very simply for us, and we have a consistent interface that we are coding to. Actually, while I'm demonstrating this, it's a good idea to consider why I'm using fields, rather than properties. There's a commonly held belief that you MUST expose properties rather than fields, but in simple cases like this, that's a load of horse-hooey. If you are only using a property to store a value, and your class isn't doing something like Serialization, then you don't need a property there.

Note that I've just knocked this together in the editor and I've not had much sleep, so there may be the odd minor typo in there. I apologise if that is the case.

GeneralRe: Example 5-14 - Drill 5-3 Pin
N8tiv23-Sep-13 1:45
N8tiv23-Sep-13 1:45 
Questionbug/challenge poll Pin
Per Söderlund22-Sep-13 20:59
Per Söderlund22-Sep-13 20:59 
AnswerRe: bug/challenge poll Pin
Richard MacCutchan22-Sep-13 21:35
mveRichard MacCutchan22-Sep-13 21:35 
GeneralRe: bug/challenge poll Pin
Per Söderlund22-Sep-13 21:40
Per Söderlund22-Sep-13 21:40 
AnswerRe: bug/challenge poll Pin
ExcellentOrg23-Sep-13 8:26
ExcellentOrg23-Sep-13 8:26 
Questionc# on my machine I have installed the virtual webcam and integrated webcam already present. So how we identify that this is virtual webcam Pin
ankur4747@yahoo.com22-Sep-13 20:04
ankur4747@yahoo.com22-Sep-13 20:04 
Questionproblem: webBrowser1.Navigate OR the loaded page? - for a jumping cursor. Pin
_Q12_22-Sep-13 7:39
_Q12_22-Sep-13 7:39 
AnswerRe: problem: webBrowser1.Navigate OR the loaded page? - for a jumping cursor. Pin
Dave Kreskowiak22-Sep-13 8:56
mveDave Kreskowiak22-Sep-13 8:56 
GeneralRe: problem: webBrowser1.Navigate OR the loaded page? - for a jumping cursor. Pin
_Q12_22-Sep-13 16:07
_Q12_22-Sep-13 16:07 
GeneralRe: problem: webBrowser1.Navigate OR the loaded page? - for a jumping cursor. Pin
_Q12_22-Sep-13 20:30
_Q12_22-Sep-13 20:30 
GeneralRe: problem: webBrowser1.Navigate OR the loaded page? - for a jumping cursor. Pin
Dave Kreskowiak23-Sep-13 1:20
mveDave Kreskowiak23-Sep-13 1:20 
QuestionC# devper in Thailand Pin
Sunsern Promsen22-Sep-13 2:16
Sunsern Promsen22-Sep-13 2:16 
AnswerRe: C# devper in Thailand Pin
OriginalGriff22-Sep-13 2:22
mveOriginalGriff22-Sep-13 2:22 
AnswerRe: C# devper in Thailand Pin
Abhinav S22-Sep-13 3:42
Abhinav S22-Sep-13 3:42 
AnswerRe: C# devper in Thailand Pin
BillWoodruff22-Sep-13 13:37
professionalBillWoodruff22-Sep-13 13:37 
GeneralRe: C# devper in Thailand Pin
Sunsern Promsen22-Sep-13 15:16
Sunsern Promsen22-Sep-13 15:16 
QuestionHow to Prevent DOM xss attack -shortened- Pin
computer_programmer121-Sep-13 5:29
computer_programmer121-Sep-13 5:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.