AalborgHTX

int.tryparse()

Feb 2nd, 2021
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApp25
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void btnGangeMedTo_Click(object sender, EventArgs e)
  21.         {
  22.             //int tal = int.Parse(txtInputTal.Text);
  23.             int tal = 0;
  24.  
  25.             bool DidPassingGoWell = int.TryParse(txtInputTal.Text, out tal);
  26.  
  27.             if (DidPassingGoWell == true)
  28.             {
  29.                 tal = tal * 2;
  30.                 lblSvarUd.Text = tal.ToString();
  31.             }
  32.  
  33.             else
  34.             {
  35.                 lblSvarUd.Text = "DU SKAL SKRIVE ET TAL";
  36.             }
  37.  
  38.            
  39.         }
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment