C# user input ⌨️

  Рет қаралды 58,396

Bro Code

Bro Code

Күн бұрын

C# user input tutorial example explained
#C# #user #input
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();
}
}
}

Пікірлер: 47
@BroCodez
@BroCodez 3 жыл бұрын
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(); } } }
@nifrez2891
@nifrez2891 2 жыл бұрын
There's a mistake in the code, 1st Console.WriteLine should have "What's your name?" in it
@snahhhhhhh
@snahhhhhhh Жыл бұрын
@@nifrez2891😂
@makmakg242
@makmakg242 9 ай бұрын
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".
@DRuger
@DRuger 2 жыл бұрын
Thank you bro I’ve been looking all night for this
@DetCoAnimeFan
@DetCoAnimeFan 3 жыл бұрын
Yay, C# tutorials!
@Someone49621
@Someone49621 11 ай бұрын
Im kinda confused, why didn't you just write int age=int.Parse(Console.ReadLine());?
@porshkabir2535
@porshkabir2535 9 ай бұрын
Because the input is considered as a string, so to use it as a integer, you need to convert it.
@bluesbr0ther588
@bluesbr0ther588 Ай бұрын
@@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.
@GHOST-fh7mw
@GHOST-fh7mw 2 жыл бұрын
thanks bro spent hours looking for this
@leocroak-toad
@leocroak-toad 9 күн бұрын
User interpolation rather than a + to tie your variables in a Console.WriteLine statement so like this Console.WriteLine($"Some text {variable}"); it is like a f string from python
@samuellundblad5766
@samuellundblad5766 8 ай бұрын
A good introduction, but I was looking for how to check for specific keypresses.
@LocgicalState
@LocgicalState 2 жыл бұрын
I keep having this problem:( "Converting null literal or possible null value to non-nullable type."
@Pain-jt8mw
@Pain-jt8mw 2 жыл бұрын
Same bro
@WickedJackThe1
@WickedJackThe1 Жыл бұрын
I think this is only avoidable by using if-statements or catching exceptions like Bro mentioned at 3:22.
@RoronoaShu27
@RoronoaShu27 Жыл бұрын
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
@raging100
@raging100 Жыл бұрын
FUCKING THANK YOU. My teacher couldnt explain this to me for DAYS
@Kelentaria
@Kelentaria Жыл бұрын
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...
@Admlostinwow
@Admlostinwow 3 жыл бұрын
You are awesome thank you
@pravaliramireddypravaliram7461
@pravaliramireddypravaliram7461 7 ай бұрын
Spr bro
@sarpcanuzel7750
@sarpcanuzel7750 2 жыл бұрын
nice video
@mahekthapa9053
@mahekthapa9053 3 ай бұрын
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
@mahekthapa9053
@mahekthapa9053 3 ай бұрын
btw i sub and like :)
@alexplaytop
@alexplaytop Жыл бұрын
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???
@muhammedshibli9522
@muhammedshibli9522 Жыл бұрын
same problem here what should i do have you fixed the issue
@I_pvn
@I_pvn 4 ай бұрын
dam congrads on 2mil
@cabdulahiibrahimcisman1950
@cabdulahiibrahimcisman1950 10 ай бұрын
// 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 ");
@ZeeWolfed
@ZeeWolfed 2 жыл бұрын
Thanks Bro i can't stop
@max-m3n
@max-m3n 9 ай бұрын
did you stop
@joem-y4s
@joem-y4s 5 ай бұрын
He Prob did​@@max-m3n
@JaspaPanatoi
@JaspaPanatoi 2 ай бұрын
how to promp user to re-enter the correct information in c# console application
@aditya_asundi
@aditya_asundi 3 жыл бұрын
what language do you specialize in? is it java?
@dixitgwda4361
@dixitgwda4361 9 ай бұрын
Somebody get this man a pizza
@viniciuslima1064
@viniciuslima1064 Ай бұрын
Thanks Bro
3 жыл бұрын
Thanks!
@spartanranger
@spartanranger 3 жыл бұрын
Thanks for the video Bro
@simik4830
@simik4830 2 ай бұрын
comment for algorithm!
@OluwatoyinTundeAyodabo
@OluwatoyinTundeAyodabo Жыл бұрын
helo, what will happen if the bro was not written and enter again
@whitedinamo
@whitedinamo 2 жыл бұрын
lesson check 😇
@K4vin60
@K4vin60 10 ай бұрын
gigachad tutorial
@juriappo354
@juriappo354 2 жыл бұрын
thanks brocode
@budderrar5751
@budderrar5751 2 жыл бұрын
noice
@Keroyz
@Keroyz 2 жыл бұрын
good shit bro code
@v4t0z
@v4t0z 3 жыл бұрын
Bro moment
@kavihassan3381
@kavihassan3381 7 ай бұрын
1k like
@memy4460
@memy4460 2 жыл бұрын
comment
@definitelynotchris4776
@definitelynotchris4776 2 ай бұрын
123
C# arithmetic operators 🧮
4:31
Bro Code
Рет қаралды 29 М.
C# methods 📞
6:05
Bro Code
Рет қаралды 62 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 21 МЛН
C# Tutorial For Beginners - Learn C# Basics in 1 Hour
1:10:32
Programming with Mosh
Рет қаралды 5 МЛН
C# variables ✖️
8:44
Bro Code
Рет қаралды 56 М.
How to Get User Input and Validate It Using C# (Simple)
3:31
Max O'Didily
Рет қаралды 12 М.
C# type casting 💱
7:15
Bro Code
Рет қаралды 55 М.
How to Program in C# - Loops (E04)
18:28
Brackeys
Рет қаралды 504 М.
C# if statements 🤔
6:27
Bro Code
Рет қаралды 49 М.
C# output 💬
4:18
Bro Code
Рет қаралды 57 М.
C# Lists 📃
6:46
Bro Code
Рет қаралды 111 М.
C# nested loops ➿
5:04
Bro Code
Рет қаралды 38 М.