Suggested Videos
In this video, we will discuss
1. Reading from the console
2. Writing to the console
3. Two ways to write to console
a) Concatenation
b) Place holder syntax – Most preferred
Code samples used in the demo
using System;
class Program
{
static void Main()
{
// Prompt the user for his name
Console.WriteLine("Please enter your name");
// Read the name from console
string UserName = Console.ReadLine();
// Concatenate name with hello word and print
Console.WriteLine("Hello " + UserName);
//Placeholder syntax to print name with hello word
//Console.WriteLine("Hello {0}", UserName);
}
}
Please note that C# is case sensitive language.
Part 2 - C# Tutorial - Reading and writing to a console
I am not able to view the videos.
ReplyDeleteWhat is the problem how to solve it suggest me.
Does it require any player to view videos.
Just goto youtube via
ReplyDeletehttp://www.youtube.com/user/kudvenkat/videos?view=1&flow=grid
you ll get all the videos and watch
Hi, thank you very much for taking time to answer and help others. Keep it up. Good Luck.
DeleteIts my pleasure sir. You are doing a lot for us ... you are one of my favourite.
DeleteHello Venkat :),
ReplyDeleteYou're doing an amazing job with these videos. Keep up the good work. It's really appreciated.
How come I can call the ReadLine method without storing its returned value in a string variable? What's happening to the returned value in this case?
Thank you :).
If you want the program to wait, without closing automatically when it has finished execution, we usually use Console.ReadLine(). Hope this answers your question.
Deletehello sir, this video has been cleared my concept about placeholder.
ReplyDeletebut only one doubt is why u not taken Console.ReadLine();
after Hello statement...
hi vinay i think that can be done....i just started reading C#...burt i can say it will work in that way also.
DeleteConsole is that black environment.
DeleteTo write to it we use Console.WriteLine and to read(input) we use Console.ReadLine().
Since, we are writing to console, so we will use Console.Write
Hi,
ReplyDeleteDo you have tutorial for windows programming ?. If so please upload them
Really nice work. Excellent job. I am new to this topic and this is very helpful to get started.
ReplyDeleteRespected Venkat sir,
ReplyDeleteI am great fan of you, you are doing great Job. Praying for your best future and prosperity.
Thanks for such a great efforts.
Hi Venkat,
ReplyDeleteI am not getting the Desired output , instead its takind the parameters and closing off.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Please enter you First name");
string Firstname = System.Console.ReadLine();
System.Console.WriteLine("Please enter you Last name");
string Lastname = System.Console.ReadLine();
System.Console.WriteLine("Hello {0} , {1}", Firstname, Lastname);
}
}
}
To see your result you can either run your program by running the application by hitting (ctrl+F5 ) or you can add System.Console.ReadLine(); like below...
DeleteSystem.Console.WriteLine("Hello {0} , {1}", Firstname, Lastname); System.Console.ReadLine();
System.Console.WriteLine("Hello {0} {1}", Firstname, Lastname);
DeleteSystem.Console.ReadLine();
Dear Sir first of all thanks for these nice and much easy to understand videos.
ReplyDeleteSir i want to get date of birth of my client and calculate it in days and months and years i cant do this can u please guid me using code?
Thanks a lot really great Great teaching, I have experienced in my Career. Can you please provide documents for C# videos. It will be great help for us.
ReplyDeleteYou can find the slides that is used in this course at
Deletehttp://csharp-video-tutorials.blogspot.se/p/c.html
Hello Sir, First of all thank you. I have a question, I have copied the exact code and it works fine but unlike your program it closes right after displaying the output... in C++ we had _getch() or system("pause") to prevent this.. what can be used here?
ReplyDeleteYou have to add following in the end of your code (in main):
DeleteConsole.ReadLine();
to make the program to stop
(or instead add in the end of yor code
Console.ReadKey();
With Console.ReadLine(); the program is waiting for an input from the user´s keyboard (followed by an Enter ) (This input is not used in this case).
OR
with Console.ReadKey(); the program is wating for ONE key to be pressed at the users´s keyboard (The code for that keyboardkey is not used in this case)
Both alternatives makes the program to stop & wait for input and
meanwhile you can see the printout.
hi venkat,
ReplyDeletePlease tell what is the difference between
Console.WriteLine("Hello " + UserName);
and
Console.WriteLine("Hello {0}", UserName);
here what is the use of place holder
console.writeline("Hello" + username) => it is called concinnate method used
DeleteConsole.WriteLine("Hello {0}", UserName) Here placeholder is used
hai venkat,
ReplyDeletemy cmd window is not displayed yet.it will suddenly disapper to run the program.which key word is used
Hey venkat,
ReplyDeleteYou Are doing a Awesome job here for The Ppl like us, From beginner to Pro everyone watches your Tutorials.
I really appreciate Your Work.
Peace:)
So... in my previous statement I need to correct and myself and tell the following. That ...
ReplyDeletethe command: string UserName = Console.ReadLine();
this ONLY command executes from the back to the front because of the assign (=) operator. So, this command is actualy two commands because of the assign operator.
And to be more specific we can tell that:
When we have int i = 10; we usualy say that i equals to 10 but the correct expression is that "the constant 10 assigned to variable i".
This thinking explains the statement that the command with the string variable and the assigned operator executes from back to front. And the Console.ReadLine() function executes before the creation of the variable UserName.
Thanks.