C# user input ⌨️

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

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

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

    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 10 месяцев назад

      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

  • @darkwing4027
    @darkwing4027 17 дней назад

    Great job on this! I'm hoping to get my certification in about 6 months time and this is a great start

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

    thanks bro spent hours looking for this

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

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

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

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

  • @Someone49621
    @Someone49621 Год назад +5

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

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

      Because the input is considered as a string, so to use it as a integer, you need to convert it.

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

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

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

    dam congrads on 2mil

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

    Spr bro

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

    nice video

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

  • @Kelentaria
    @Kelentaria 2 года назад +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...

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

    Thanks Bro i can't stop

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

      did you stop

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

      He Prob did​@@max-m3n

  • @leocroak-toad
    @leocroak-toad Месяц назад

    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

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

    Somebody get this man a pizza

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

    Thanks for the video Bro

  •  3 года назад

    Thanks!

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

    Thanks Bro

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

    what language do you specialize in? is it java?

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

    lesson check 😇

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

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

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

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

    gigachad tutorial

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

    comment for algorithm!

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

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

    thanks brocode

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

    noice

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

    good shit bro code

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

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

  • @cabdulahiibrahimcisman1950
    @cabdulahiibrahimcisman1950 11 месяцев назад

    // 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 ");

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

    Bro moment

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

    1k like

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

    123

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

    comment