12,896,517 members (58,572 online)
Rate this:
See more:
hi, does any one can tell me how to give the value from keyboard not to be static in application, this is the part of code here is value static:

`var city = new city(5);`

and this is a class
```class city
{

public city(int Size)
{

_size = Size;
_num= new int[_size];
}```

this is just to adapt you with code.... this number that is in new city(5). I want to enter from tast,,but I cant...
Posted 22-Dec-12 5:00am
h5h6692
Updated 22-Dec-12 5:02am
ProgramFOX196.1K
v2
Krunal Rohit 22-Dec-12 11:06am

enter from tast ??

Rate this:

## Solution 1

Hi,

Try this:
```int cityInt = -1;
try
{
}
catch
{
Console.WriteLine("Input isn't an integer!");
}
if (cityInt != -1)
{
var city = new city(cityInt);
}```

Hope this helps.
h5h6 22-Dec-12 11:52am

thnx it works. :)
ProgramFOX 22-Dec-12 11:53am

You're welcome!
h5h6 22-Dec-12 12:12pm

hey man, I change the way of code and again problem to give value from keyboard:
this is a class:
class Boardi
{
public static int N;

private int[] board;
private int col;
public Boardi()
{
board = new int[N + 1];
city= 1;
}

and a list:
static List<boardi> findSolutions(int city, List<boardi> allSolutions)
{
if (city> Boardi.N)
return allSolutions;
ProgramFOX 22-Dec-12 12:15pm

To get input, use this line:
`Console.ReadLine();`
That returns a string. To convert it to an int, use `Convert.ToInt32`:
``` int cityInt = Convert.ToInt32(Console.ReadLine()); ```
h5h6 22-Dec-12 12:25pm

Yes I use int.parse the same thing.
but i that second case here is different to input value from keyboard because I have a list as u see.... !!
ProgramFOX 22-Dec-12 12:27pm

And what's the problem?
h5h6 22-Dec-12 12:34pm

the same to input the character from tastier:
here is the clas
class Boardi
{
public static int N;

private int[] board;
private int col;
public Boardi()
{
board = new int[N + 1];
city= 1;
}
and how to give a number to the parameter N
I tried with object:
Boardi p=new Boardi()
and then p.N to direct to N..... but dont work.......
ProgramFOX 22-Dec-12 12:36pm

Like this:``` Boardi.N = ... ```
h5h6 22-Dec-12 12:51pm

int value;
value= Boardi.N;
but dont work
I think in a class Boardi maybe we must do something... because parameter N should take value...
ProgramFOX 22-Dec-12 12:53pm

No, do this:
``` Boardi.N = int.Parse(Console.ReadLine()); ```
h5h6 22-Dec-12 12:56pm

thnx thnx thnx....I appreciate that :)
It Works man :)
ProgramFOX 22-Dec-12 12:57pm

You're welcome!

Top Experts
Last 24hrsThis month
 OriginalGriff 290 CHill60 155 ppolymorphe 110 Richard MacCutchan 85 Vinod Jangle 60
 OriginalGriff 5,422 CHill60 3,673 Jochen Arndt 2,958 Karthik Bangalore 2,456 ppolymorphe 2,375