learning to code - question on dictionary example

L

Learning to code

Hello,

I'm am learning to program and hoping someone could help me with my code question.

Below I have pasted the C# dictionary code example I am working on. The intent of the program is to ask a user a question, read their response, and respond back to the user. This is a counsel application written in C#, usingthe visual studio 2010 express edition.

Reviewing the code below, where I am stuck is on this line:

Console.WriteLine("my response is {0}",dict[myInput]);

What I would like the program to do is read the response the user entered, find the key within the dictionary, and respond back to the user based on the value for that key.

I believe what is incorrect above is where I am trying to pass in the string value from the myInput variable, into the dictionary.

If the program worked correctly - it would ask the user their name, if the user typed "tara", it would respond back "Hi Tara!" (based on the string value in the dictionary).


using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
public class Example
{
public static void Main()
{
// Create and initilize dictionary of strings.
Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("Tara", "Hi Tara!");
dict.Add("Ryan", "Hi Ryan!");

//Introduction
Console.WriteLine("What is your name?");

//Read Answer
String myInput = Console.ReadLine();

//Respond
Console.WriteLine("my response is {0}",dict[myInput]);

//Stop
Console.ReadLine();
}
}
}
 
K

Keith Thompson

Learning to code said:
thank you! I removed the incorrect post as well.

No, you didn't. You may have removed it from Google Groups, but it
still shows up on my Usenet server. (Don't worry about it, though; just
be aware that you can't generally delete anything you've posted to Usenet.)
 
T

tom st denis

No, you didn't.  You may have removed it from Google Groups, but it
still shows up on my Usenet server.  (Don't worry about it, though; just
be aware that you can't generally delete anything you've posted to Usenet..)

It'd work if your server honoured cancel requests but since they're
ridiculously easy to forge nobody does...

I have to question just how naive the fathers of the Internet were...

If people signed their posts they could sign cancel requests too ...
but we're still decades out from implementing 1990s technology...

Now don't get me started on why we still use "passwords" to login to
servers...

Tom
 
G

Geoff

I have to question just how naive the fathers of the Internet were...

Just read the RFC's. I can't recall a single instance of any of them
designing-in any decent authentication mechanisms. In those days,
everyone played by the rules and encryption was never used. To be
fair, I don't think anyone gave much thought to built-in resistance to
exploitation because it was all just a research tool and fun times
between labs. All the geeks were equally baffled when the Morris worm
emerged. How could anyone mess with their beautiful net?
 
P

Patrick Scheible

tom st denis said:
It'd work if your server honoured cancel requests but since they're
ridiculously easy to forge nobody does...

I have to question just how naive the fathers of the Internet were...

There wasn't a good way to sign Usenet posts, or e-mail, that would run
in minimal time and space on a 1970s system. Given no way to do it that
would stop forgery, better not to do it at all so undergrads around the
world wouldn't take it as a challenge.

-- Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top