Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I want to use user input string for a function like this :

int x = 5;
int y = 3;
int z = 2;

string userInput;
consol.read(userinput);

//what should I do to get this answer when user entered x 
...

consol.write("You have entered X , X is 5");



I do not want to find user input with if like :
if(userinput == "x")
{
consol.write("You have entered X , X is 5");
}


I want something like pointer .

thanks.
Posted
Updated 30-Jun-10 3:11am
v2
Comments
Toli Cuturicu 5-Jul-10 16:47pm    
Reason for my vote of 1
1. will not compile at all
2. homework
3. fixation on pointers

A few issues here.

  1. consol.read(userinput); is incorrect because

    • The method is Console.Read(); Clickety[^]
    • It takes no parameters.
    • It returns an int.

  2. The retrieved int would need to be converted to the actual numerical value rather than the keycode it represents so it can be compared.
  3. You could get the pointer but it won't be any use as the pointer to x will be different to the value of the user input even if the same.
 
Share this answer
 
Use a Dictionary, see [^].
:)
 
Share this answer
 
Comments
Fullmm 30-Jun-10 9:37am    
No , I only want to use pointer , Pointer help me when I want to use enum values in windows forms and use the.
Abhinav S 30-Jun-10 13:09pm    
Managed code considers pointers to be unsafe.
Don't insist on something - when someone provides you with a solution dont argue. Thanks.
I dont know if I understand what exactly you want, but here is the way to use pointers in C#:

Your code must be "unsafe", wherever you want pointers to work;

Ex:

unsafe class MyClass
{

}


-But how to alow that? You will ask.
Go to "Project" up in your studio an choose "YourProjectName" properties,
Then in "compile" option (second option from up to below if you use visual studio) an mark the checkbox "Allow unsafe cod"

Obs.: My visual studio is in other language so sorry if I wrote some wrong option, but I gave to you the location and the idea.

Hope this help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900