|
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
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.
|
|
|
|
|
Okay, thank you for your response and your feedback/constructive criticism…
I myself haven't had much sleep when I finished this little exercise… I should have set it up a little better…
This exercise came at the end of chapter 5, it was discussing the basics of inheritance, properties, read-only and const keywords…
I'm guessing the book just wanted me to practice writing code for inheritance and properties…
With that said, I do realize I could have just created an object in the main method to ask the user to enter a Social Security number and age…
I just want to practice, and throwing in a constructor…
|
|
|
|
|
Have you guys ever found a bug or misbehaviour that you were unable to correct?
I´ve had a bug haunting me for weeks that makes me wonder if there are unsolveable bugs out there.
I lack experience since ive only been coding proffessionally for 5 years.
If you had one,what was it and what made you give up?
(I´m coding in C#, thats why i posted it on this forum.)
|
|
|
|
|
Söderlund wrote: I´m coding in C#, thats why i posted it on this forum Well, it's the wrong place, this forum is for technical questions; try the Lounge[^] for this type of discussion.
Veni, vidi, abiit domum
|
|
|
|
|
|
What is ur bug.... I think in one of the Dilbert's cartoon, they'd once shown using a real hammer to debug the application and against properly aimed hammer, no bugs (or hard drives carrying the bugs) stand a chance.
|
|
|
|
|
I am working on automatically find which webcam is working properly on my machine. Condition: 1) If you have two webcam one working and another one is not working. And the not working is in 0th position so is comes first so code taking 0th position.
2) If you installed a virtual webcam and integrated webcam already present so how to identify that which is a virtual or working webcam.
|
|
|
|
|
For each (char)character I wrote in textBox1, the webBrowser1.Navigate is fired.
The problem is that the mouse cursor JUMP from my textbox1 into webBrowser1, and I don't figure out WHY is doing that on this PARTICULAR PAGE(see code). On other pages i see is working fine, but here, is going nuts. I think is (part) because of the webBrowser1.Navigate method, and (part) because of the page. I need help on this matter. Its impossible for me to resolve it.
private void textBox1_TextChanged(object sender, EventArgs e)
{
webBrowser1.Navigate("http://translate.google.com/?hl=en&tab=wT#en|ro|" + textBox1.Text);
}
Thanks.
|
|
|
|
|
It's doing that probably because the page is coded to set one of its textboxes as the one that souls have the focus. There's nothing you can do to change that behavior. A better solution would be to not use Google's Translate page but instead use a service to do the translation and your code just displays the result in a textbox. You're relying on things that you have no control over.
|
|
|
|
|
ok, thanks... but is a very big loss,pity,...eh. |
|
|
|
|
|
Can you direct me to a sample for using what you suggesting: "use a service to do the translation"?
It is real? There are dictionaries other than sites on internet? I downloaded one with 30k word + samples, synonyms and explanations for each word, but i never been able to put it in practice. Its a very elaborate PERSONAL project... and i'm single(no help from anybody). I am crazy to even think to such a project. But, please enlighten me -- i do it for fun, and with love for what i like.
Thanks again.
|
|
|
|
|
|
is there any C# developer in Thailand?
|
|
|
|
|
Yes.
There are C# developers in Thailand.
However, this is not a jobs board.
The only instant messaging I do involves my middle finger.
|
|
|
|
|
|
Sawasdee Khrup, Khun Sunsern.
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Hi Bill,
How're you?
I'm looking for some good C# developers to join my project in Bangkok. Would you suggest? (Thai developer)
Best regards
|
|
|
|
|
1-How to make a sandbox that sandboxing and preventing Malicous Java script at URL address bar with such permissions like never change the title page , never change the images or flash or any other multimedia from outside in the page and never excute a code from outside ?
2-after detecting and preventing through Sandbox , how to take the piece of code which causes the problem from a big malicious script ? e.g. eval() is the responsible for making the problem so i want the program to catch for the 3rd step
3-if for example eval() is the bad function which causes the trouble then how to REPLACE it -mapping- with a safe function? -lets say only a mapping for eval() ,execScript , SetTimeOut , SetTimeInterval
innerHTML , outerHTML document.cookies, location.replace , location.assign , script.src href , src , Iframe -
I red many articles but i didnt find safe mapping for unsafe functions
What are the safe mapping for those unsafe functions or properties??
I red this it was helpful but not complete:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval[^]
|
|
|
|
|
|
I need to set voucher print c# window form application How i can set that please Help Me.....
|
|
|
|
|
|
Hi guys, I need Basic Basic Silverligt Projects Pls suggest me a link. Thanks in Advance
|
|
|
|
|
|
|
Hi everyone I hope you all are fine and happy.
I need some help here and i will not forget this favor.
This problem is about protecting the users from Malicious DOM Scripts Attacks that the users may be tricked to execute in his/her Browser.
I will explain What is DOM and What is DOM XSS Attack and if you are already know that you can go to
OK OK What do I need here? to what my plan is and then read My Straight Questions which is the section i want the help from you and I hope you will help me instantly
Now I will explain What DOM and What DOM Based XSS attacks briefly:
First of all (DOM defenition):
DOM is for Document Object Model it is the Tree that any web site or a web application uses , nowadays almost every web site or web application has DOM.
as a great advantage to users , DOM can be used as a good facility for users to access and Manipulate DOM Tree according to user's preferences with a dynamic script language like Java script.
a good example about when a user can modify and manipulate DOM is when user can change the web page's Title or the web page's background color.
The Danger of DOM Based XSS:
DOM Based XSS Attack is when a hacker Modify DOM with a script in a way that a server will never want to , and not according to user's preferences but according to the attackers bad intentions.a hacker or an attacker can trick or persuade the client to run a malicious script to make a DOM attack.
DOM Based XSS Attack is the third type of XSS Vulnerability , sometimes referred as XSS Type 0 Vulnerability which is when the attacker exploits a vulnerable web page to DOM vulnerability and let clients (users) execute and run Malicious DOM scripts at their machines -server never interfere with that- and thus without the wise of clients the server reputation is not good specially if a malicious hackers for example put a bad insults in the title tag to insult the client when visits it because the Malicious DOM Scripts exploits the vulnerabilities of a web page and the Updating and modification of DOM has happened.
OK OK What do I need here?
I need to make a simple tool that prevent DOM based XSS vulnerability which occurs at client side with 4 steps , 3 steps are main steps and the 4th step is optional.
This tool is a windows Application runs at client side.
This tool has a sandbox to prevent the Malicious java script Attacks then take the bad script and extract the tiny point which causes an attack FINALLY it will convert the bad function which causes the attack for example using the dangerous eval() function to a good function and safe function like JSON method. ONLY IF IT POSSIBLE
1-It is a simple browser with its address bar that when a user put a URL ..... a SANDBOX will start and this sandbox will inspect if this URL contains a Malicious Java script (Malicious DOM) then it will detect it and make it stop and never run it in the browser.
I studied and tried the AppDomain class and SecurityManager.GetStandard Method but all of them are for making a sandbox for .exe and Assembly Binary Files I studied Iframe sand Box too and how to sandbox HTML by Iframe and DOM Cheat Sheet in OWASP but i was confused because I don't want to only prevent but instead want to prevent then convert the malicoius scipt to good script the run the good script
2-After the detection of that Malicious DOM it will take that script and take the exact unsafe script point (the unsafe code which refers as unsafe sinks which is the UNSAFE Function) example
3-After taking the exact unsafe DOM code point it will try to convert the unsafe sinks to safe sink for example converting eval() function if causes a malicious script to a good function that may not make trouble if it be used.
4-Contact the server's Web Master to tell him that the server's web page has a vulnerability and tell the developer how to fix these vulnerabilities.
My Straight Questions
1-How to make a sandbox that sandboxing and preventing Malicous Java script at URL address bar with such permissions like never change the title page , never change the images or flash or any other multimedia from outside in the page and never excute a code from outside ?
2-after detecting and preventing through Sandbox , how to take the piece of code which causes the problem from a big malicious script ? e.g. eval() is the responsible for making the problem so i want the program to catch for the 3rd step
3-if for example eval() is the bad function which causes the trouble then how to REPLACE it -mapping- with a safe function? -lets say only a mapping for eval() ,execScript , SetTimeOut , SetTimeInterval
innerHTML , outerHTML document.cookies, location.replace , location.assign , script.src href , src , Iframe -
I red many articles but i didnt find safe mapping for unsafe functions
What are the safe mapping for those unsafe functions or properties??
I red this it was helpful but not complete:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval[^]
Optional:
4-How to contact with the server site to tell it that it hass a DOM a vulnerability even if we don't have its Web Master email??
5- What are the suggestions for fixing vulnerabilities at the server side??
Notes:
A-Actually I invented this Algorithm to protect clients even if they were tricked to run malicious java scripts what I only need is the help to implement this programmitically , but if you have some other or simpler algorithm than this you are welcomed to tell me about yours or even if modify my algorithm if you see it can make some enhancements.
B-I want this tool to be implemented with C# Language , but if you can make this algorithm and implement it programmitically in ANY OTHER LANGUAGE feel free to post your solution with the language you know well and like
C-one of my principles is to always try and I tried many times in making this and I would never post this but I have really a limited time and something like dead line
I really Really Need help asap
Thank you very much
|
|
|
|
|