using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { Console.WriteLine("What's your age?"); String name = Console.ReadLine(); Console.WriteLine("What's your age?"); int age = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Hello " + name); Console.WriteLine("You are " + age + " years old"); Console.ReadKey(); } } }
I'm having a problem with the input program i've made with this code: using System; namespace DataTypesApp { class DataTypesProgram { static void Main(string[] args) { Console.Write("Enter the pieces of apples: "); int num = Convert.ToInt32(Console.Read()); Console.Write("Enter total price of "+ num +" apple(s): "); double num2 = Convert.ToInt32(Console.Read()); Console.ReadKey(); } } } During the program window, after I set the input number I have to the num variable, the num value should be rightfully seen based on what number I put there (for example, I input 6, where in the next sentence it should say "Enter total price of 6 apple(s): "), instead it adds 48 values off from the num variable from some unknown reason why ("Enter total price of 54 apple(s): "). We were using Visual Studio 2017 because our prof said that using the recent version is "Cheating".
@@porshkabir2535 But int.Parse does actually convert a string to an int too, it would have given the same result. The difference is that int.Parse can only convert strings while Convert.ToInt32 can convert other data types too.
Ive found an explanation on Stackoverflow for the same problem I have currently now: Firstly, you are seeing this message because you have the C# 8 Nullable reference type feature enabled in your project. Console.ReadLine() returns a value that can be either a string or null but you are using it to set a variable of type string. Instead either use the var keyword which will implicitly set your variable to the same type as the return value or manually set your variable as type nullable string string?. the ? denotes a nullable reference type. You may then want to check that your variable does infact hold a string before you use it: string? NumInput = Console.ReadLine(); if (NumInput == null) { // ... } Written by Sean McCafferty To make it short: just put between string and name a ? and it should work. string? name
hello Sir me first time here :) i was looking for user input code i am new to coding but really wanted to learn can you make code for user input with small simple interface black background with no buttons just text line which i can type and hit enter and get output as string please
Why my program after input asks me input again My Name? It's simple ReadLine program, but after I input, nothing happens, just another empty line for inputting text???
// user input Console.WriteLine("please enter your first Name:"); string firstName = Console.ReadLine(); Console.WriteLine("please enter your second Name:"); string secondName = Console.ReadLine(); Console.WriteLine("please enter your last Name:"); string lastName = Console.ReadLine(); Console.WriteLine("please enter your Age:"); string age = Console.ReadLine(); Console.WriteLine("your full name is : " +firstName+secondName+lastName + " and your age is " + age +" years old ");
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("What's your age?");
String name = Console.ReadLine();
Console.WriteLine("What's your age?");
int age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Hello " + name);
Console.WriteLine("You are " + age + " years old");
Console.ReadKey();
}
}
}
There's a mistake in the code, 1st Console.WriteLine should have "What's your name?" in it
@@nifrez2891😂
I'm having a problem with the input program i've made with this code:
using System;
namespace DataTypesApp
{
class DataTypesProgram
{
static void Main(string[] args)
{
Console.Write("Enter the pieces of apples: ");
int num = Convert.ToInt32(Console.Read());
Console.Write("Enter total price of "+ num +" apple(s): ");
double num2 = Convert.ToInt32(Console.Read());
Console.ReadKey();
}
}
}
During the program window, after I set the input number I have to the num variable, the num value should be rightfully seen based on what number I put there (for example, I input 6, where in the next sentence it should say "Enter total price of 6 apple(s): "), instead it adds 48 values off from the num variable from some unknown reason why ("Enter total price of 54 apple(s): ").
We were using Visual Studio 2017 because our prof said that using the recent version is "Cheating".
Yay, C# tutorials!
Thank you bro I’ve been looking all night for this
Im kinda confused, why didn't you just write int age=int.Parse(Console.ReadLine());?
Because the input is considered as a string, so to use it as a integer, you need to convert it.
@@porshkabir2535
But int.Parse does actually convert a string to an int too, it would have given the same result.
The difference is that int.Parse can only convert strings while Convert.ToInt32 can convert other data types too.
A good introduction, but I was looking for how to check for specific keypresses.
thanks bro spent hours looking for this
God, I spent so much time trying to figure this out... I am a little annoyed it was that easy... :/ I kept forgetting one string...
I keep having this problem:( "Converting null literal or possible null value to non-nullable type."
Same bro
I think this is only avoidable by using if-statements or catching exceptions like Bro mentioned at 3:22.
Ive found an explanation on Stackoverflow for the same problem I have currently now:
Firstly, you are seeing this message because you have the C# 8 Nullable reference type feature enabled in your project. Console.ReadLine() returns a value that can be either a string or null but you are using it to set a variable of type string. Instead either use the var keyword which will implicitly set your variable to the same type as the return value or manually set your variable as type nullable string string?. the ? denotes a nullable reference type.
You may then want to check that your variable does infact hold a string before you use it:
string? NumInput = Console.ReadLine();
if (NumInput == null)
{
// ...
}
Written by Sean McCafferty
To make it short: just put between string and name a ? and it should work.
string? name
You are awesome thank you
FUCKING THANK YOU. My teacher couldnt explain this to me for DAYS
Spr bro
how to promp user to re-enter the correct information in c# console application
nice video
Thanks Bro
hello Sir me first time here :) i was looking for user input code i am new to coding but really wanted to learn can you make code for user input with small simple interface black background with no buttons just text line which i can type and hit enter and get output as string please
btw i sub and like :)
dam congrads on 2mil
Thanks Bro i can't stop
did you stop
He Prob did@@max-m3n
Thanks!
Thanks for the video Bro
Why my program after input asks me input again My Name? It's simple ReadLine program, but after I input, nothing happens, just another empty line for inputting text???
same problem here what should i do
have you fixed the issue
what language do you specialize in? is it java?
// user input
Console.WriteLine("please enter your first Name:");
string firstName = Console.ReadLine();
Console.WriteLine("please enter your second Name:");
string secondName = Console.ReadLine();
Console.WriteLine("please enter your last Name:");
string lastName = Console.ReadLine();
Console.WriteLine("please enter your Age:");
string age = Console.ReadLine();
Console.WriteLine("your full name is :
" +firstName+secondName+lastName + " and your age is " + age +" years old ");
helo, what will happen if the bro was not written and enter again
noice
Somebody get this man a pizza
lesson check 😇
thanks brocode
comment for algorithm!
gigachad tutorial
good shit bro code
Bro moment
1k like
123
comment