From: sahel on
Hi ;
I wrote a program that it has error if u have time plz help me;

It must get 5 char from user (without pressing Enter key)
Than shows each of the char in different line
But it has this error : Error 1 Cannot implicitly convert type
'System.ConsoleKeyInfo' to 'char'

using System;
class Program
{
static void Main(string[] args)
{
ConsoleKeyInfo d;
char [] string1=new char [5];
for (int i = 0; i < 5; i++)
{
d= Console.ReadKey(false);
string1[i]=d;
}
for (int i = 0; i < 5; i++)
{
Console.WriteLine(string1[i]);
}

}
}
From: Arne Vajhøj on
On 14-03-2010 14:01, sahel wrote:
> I wrote a program that it has error if u have time plz help me;
>
> It must get 5 char from user (without pressing Enter key)
> Than shows each of the char in different line
> But it has this error : Error 1 Cannot implicitly convert type
> 'System.ConsoleKeyInfo' to 'char'
>
> using System;
> class Program
> {
> static void Main(string[] args)
> {
> ConsoleKeyInfo d;
> char [] string1=new char [5];
> for (int i = 0; i< 5; i++)
> {
> d= Console.ReadKey(false);
> string1[i]=d;
> }
> for (int i = 0; i< 5; i++)
> {
> Console.WriteLine(string1[i]);
> }
>
> }
> }

Try:

string1[i]=d;

->

string1[i]=d.KeyChar;

Arne
From: sahel on
On Mar 14, 9:08 pm, Arne Vajhøj <a...(a)vajhoej.dk> wrote:
> On 14-03-2010 14:01, sahel wrote:
>
>
>
> > I wrote a program that it has error if u have time plz help me;
>
> > It must get 5 char from user (without pressing Enter key)
> > Than shows each of the char in different line
> > But it has this error : Error      1       Cannot implicitly convert type
> > 'System.ConsoleKeyInfo' to 'char'
>
> > using System;
> >      class Program
> >      {
> >          static void Main(string[] args)
> >          {
> >              ConsoleKeyInfo d;
> >              char [] string1=new char [5];
> >              for (int i = 0; i<  5; i++)
> >              {
> >                   d= Console.ReadKey(false);
> >                   string1[i]=d;
> >              }
> >              for (int i = 0; i<  5; i++)
> >              {
> >                  Console.WriteLine(string1[i]);
> >              }
>
> >          }
> >      }
>
> Try:
>
> string1[i]=d;
>
> ->
>
> string1[i]=d.KeyChar;
>
> Arne

thank Arne ;
what u did that now u r very good at c#
From: mick on
"sahel" <nam.nam.barooon(a)gmail.com> wrote in message
news:d455bd04-6206-4986-8cd3-8eae93a04de1(a)q23g2000yqd.googlegroups.com...
> Hi ;
> I wrote a program that it has error if u have time plz help me;
>
> It must get 5 char from user (without pressing Enter key)
> Than shows each of the char in different line
> But it has this error : Error 1 Cannot implicitly convert type
> 'System.ConsoleKeyInfo' to 'char'
>
> using System;
> class Program
> {
> static void Main(string[] args)
> {
> ConsoleKeyInfo d;
> char [] string1=new char [5];
> for (int i = 0; i < 5; i++)
> {
> d= Console.ReadKey(false);
> string1[i]=d;
> }
> for (int i = 0; i < 5; i++)
> {
> Console.WriteLine(string1[i]);
> }
>
> }
> }


string1[i] = d.KeyChar

mick

From: Peter Duniho on
sahel wrote:
> Hi ;
> I wrote a program that it has error if u have time plz help me;
>
> It must get 5 char from user (without pressing Enter key)
> Than shows each of the char in different line
> But it has this error : Error 1 Cannot implicitly convert type
> 'System.ConsoleKeyInfo' to 'char'

Start here:
http://msdn.microsoft.com/en-us/library/471w8d85.aspx

You have a number of questions that are probably better-answered by a
true beginners-oriented forum, book, training course, etc. But barring
that�

Functions have return value types. Functions that return nothing still
have a return type of "void" and any other function will return a value
of the type declared for the function.

You can see from the documentation above that the ReadKey() method does
not return a "char" type (where "char" is simply an alias for
"System.Char"). But, if you look closely at the documentation for the
type it _does_ return ("System.ConsoleKeyInfo"), you will find a
property (I will leave the finding of that property as an exercise for
you, the reader) in that type that returns the _actual_ "char" for the
key pressed, assuming one exists.

And note: there won't necessarily be a proper "char" value for every key
that might be pressed, because not every key on the keyboard corresponds
to a specific Unicode character. That's why ReadKey() returns a more
general-purpose value than just a plain character. So that console
applications can react precisely to specific key inputs, rather than
being limited to what can be represented as text (getch() "solves" this
by returning special character sequences instead�not a very good
solution, frankly).

Pete