简体   繁体   中英

C# Algorithm 'out'

every time I try to compile this I get an error saying: 'Invalid expression term 'out'. Any ideas on what this means? Thanks.

using System;

class AlgorithmTest
{
    public static void Main( string[] args )
    {

    int N = 5; 

        for (int i=1; i<=N; i=i+1){
        out.print(i);}
        for (int j=1; j<=N; j=j+1){
        out.print(j);}

        Console.ReadLine();
    }

}

Like KIllercam says you need Console.Writeline(string)

int N = 5;

for (int i = 1; i <= N; i = i + 1)
{
    Console.WriteLine(i.ToString());
}
for (int j = 1; j <= N; j = j + 1)
{
    Console.WriteLine(j.ToString());
}


Console.ReadLine();

Console.WriteLine() will print in new line, if you want to print in one line without line break you can use Console.Write()

It means there that out is indeed an invalid expression, the compiler is right.

Try

Console.WriteLine(j.ToString());

I hope this helps.

If you want to write to the standard-output-stream use Console.Out instead:

Console.Out.WriteLine("yourTextHere");

The out the compiler complains about is indeed a keyword which cannot be used for this purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM