- 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int age = Convert.ToInt32(Console.ReadLine()); int broAge = Convert.ToInt32(Console .Readline()); Console.WriteLine("You are {0} years old", "your bro is {1}", age, broAge ); } } }
please tell me whats wrong in this code?
8 Antworten
+ 1
You can only use " " at once
+ 1
If you want to add multiple strings in a Console.WriteLine(); You must seperate them with a +.
Console.WriteLine("You are {0} years old," + "your bro is {1}", age, broAge );
+ 1
You may use:
Console.WriteLine("You are " + age + " years old, your bro is " + broAge );
instead so that you will not be confused on how to use { }
+ 1
Since Visual Studio 2015 we can now do it like:
Console.WriteLine(quot;Your are {age} years old and your bro is {broAge} old");
This saves a lot of space when the strings get more complicated. 
+ 1
you make mistakes in spelling of "Readline" and "ReadLine"
0
The problem it's at --years old", "your bro is-- 
If you wish to concatanate this it's not the way.
For you code to work you must write:
Console.WriteLine("You are {0} years old, your bro is {1}", age, broAge);
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SearchApplication
{
    class Program
    {
        static void Main(string[] args)
        { int[] LA = {1,3,5,7,8}; 
          int item = 5, n = 5; 
          int i = 0, j = 0; 
         Console.WriteLine("The original array elements are :"); 
  
         for(i = 0; i<n; i++) { 
          Console.WriteLine("LA[{0}] = {1}", i, LA[i]); 
   } 
     
   while( j < n){ 
      if( LA[j] == item ){ 
         break; 
      } 
      j = j + 1; 
   } 
 
   Console.WriteLine("Found element {0} at position {1}", item, j+1);
   Console.ReadKey();
        }
    }
}
0
     programs
#Program 1 Variables
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EAU_ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            string name = "Hassan ";
            int age = 30;
            Console.WriteLine(name);
            Console.WriteLine(age);
        }
    }
}
#Program 2 If Statement
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ifstatement
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please Enter a Number ");
            int num = int.Parse(Console.ReadLine());
            if(num % 2 == 0)
            {
                Console.WriteLine("It is an Even Number");
            }
                
        }
    }
}
#Program 3 If-Else Statement
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ifelsestatement
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please Enter a Number ");
            int num = int.Parse(Console.ReadLine());
            if(num % 2 == 0)
            {
                Console.WriteLine("It is an Even Number");
            }
            else
            {
                Console.WriteLine("It is an Odd Number");
            }     
        }
    }
}
#Program 4 Switch statement three
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace switchcase
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int day = 4;
            switch (day)
            {
                case 1:
                    Console.WriteLine("Monday");
                    brea



