- 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?
7 ответов
+ 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();
}
}
}