C# user input ⌨️

Поделиться
HTML-код
  • Опубликовано: 1 дек 2024

Комментарии • 46

  • @BroCodez
    @BroCodez  3 года назад +25

    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 года назад +1

      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".

  • @DetCoAnimeFan
    @DetCoAnimeFan 3 года назад +9

    Yay, C# tutorials!

  • @DRuger
    @DRuger 2 года назад +3

    Thank you bro I’ve been looking all night for this

  • @Someone49621
    @Someone49621 11 месяцев назад +5

    Im kinda confused, why didn't you just write int age=int.Parse(Console.ReadLine());?

    • @porshkabir2535
      @porshkabir2535 9 месяцев назад +1

      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.

  • @samuellundblad5766
    @samuellundblad5766 7 месяцев назад

    A good introduction, but I was looking for how to check for specific keypresses.

  • @GHOST-fh7mw
    @GHOST-fh7mw 2 года назад +1

    thanks bro spent hours looking for this

  • @Kelentaria
    @Kelentaria Год назад +2

    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...

  • @LocgicalState
    @LocgicalState 2 года назад +3

    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

  • @Admlostinwow
    @Admlostinwow 3 года назад +1

    You are awesome thank you

  • @raging100
    @raging100 Год назад +1

    FUCKING THANK YOU. My teacher couldnt explain this to me for DAYS

  • @pravaliramireddypravaliram7461
    @pravaliramireddypravaliram7461 7 месяцев назад

    Spr bro

  • @JaspaPanatoi
    @JaspaPanatoi 2 месяца назад

    how to promp user to re-enter the correct information in c# console application

  • @sarpcanuzel7750
    @sarpcanuzel7750 2 года назад +1

    nice video

  • @viniciuslima1064
    @viniciuslima1064 28 дней назад

    Thanks Bro

  • @mahekthapa9053
    @mahekthapa9053 2 месяца назад

    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

  • @I_pvn
    @I_pvn 4 месяца назад

    dam congrads on 2mil

  • @ZeeWolfed
    @ZeeWolfed 2 года назад

    Thanks Bro i can't stop

    • @max-m3n
      @max-m3n 8 месяцев назад +1

      did you stop

    • @joem-y4s
      @joem-y4s 5 месяцев назад

      He Prob did​@@max-m3n

  •  3 года назад

    Thanks!

  • @spartanranger
    @spartanranger 3 года назад

    Thanks for the video Bro

  • @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

  • @aditya_asundi
    @aditya_asundi 3 года назад

    what language do you specialize in? is it java?

  • @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 ");

  • @OluwatoyinTundeAyodabo
    @OluwatoyinTundeAyodabo Год назад

    helo, what will happen if the bro was not written and enter again

  • @budderrar5751
    @budderrar5751 2 года назад

    noice

  • @dixitgwda4361
    @dixitgwda4361 9 месяцев назад +1

    Somebody get this man a pizza

  • @whitedinamo
    @whitedinamo 2 года назад

    lesson check 😇

  • @juriappo354
    @juriappo354 2 года назад

    thanks brocode

  • @simik4830
    @simik4830 2 месяца назад

    comment for algorithm!

  • @K4vin60
    @K4vin60 9 месяцев назад

    gigachad tutorial

  • @Keroyz
    @Keroyz 2 года назад

    good shit bro code

  • @v4t0z
    @v4t0z 3 года назад

    Bro moment

  • @kavihassan3381
    @kavihassan3381 6 месяцев назад

    1k like

  • @definitelynotchris4776
    @definitelynotchris4776 2 месяца назад

    123

  • @memy4460
    @memy4460 2 года назад

    comment