Reverse Of Number In UWP

Now we will see how to create a UWP for calculating the reverse of an entered number. First open Visual Studio IDE 2017, then Open new project.Then, select Visual C# and Blank App.



Now, select the Target Version and Minimum Version.



Now, in solution explorer open MainPage.xaml.

Now in toolbox select the TextBlock and drag it on the screen.



In toolbox select TextBox and drag it on the screen.



Now again repeat the same for TextBlock and for TextBox. And in toolbox select Button and drag it on the screen.



And now edit the properties of TextBlocks,TextBoxes and Button and your screen will appear like this



Now the xaml code will be,
  1. <Page x:Class="Reverse_Of_Number.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Reverse_Of_Number" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">  
  2.     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
  3.         <TextBlock x:Name="tbnum" HorizontalAlignment="Left" Height="99" Margin="286,214,0,0" Text="Enter any number:" TextWrapping="Wrap" VerticalAlignment="Top" Width="353" FontSize="36" />  
  4.         <TextBox x:Name="txtnum" HorizontalAlignment="Left" Height="84" Margin="687,210,0,0" Text="" VerticalAlignment="Top" Width="376" FontSize="36" />  
  5.         <TextBlock x:Name="tbres" HorizontalAlignment="Left" Height="72" Margin="298,341,0,0" Text="Result:" TextWrapping="Wrap" VerticalAlignment="Top" Width="333" FontSize="36" />  
  6.         <TextBox x:Name="txtres" HorizontalAlignment="Left" Height="72" Margin="679,325,0,0" Text="" VerticalAlignment="Top" Width="392" FontSize="36" />  
  7.         <Button x:Name="btncal" Content="Calculate" HorizontalAlignment="Left" Height="100" Margin="456,476,0,0" VerticalAlignment="Top" Width="417" FontSize="36" /> </Grid>  
  8. </Page>  


Now double click on the Button and it will open a .cs file and then write the code in that file
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.IO;  
  4. using System.Linq;  
  5. using System.Runtime.InteropServices.WindowsRuntime;  
  6. using Windows.Foundation;  
  7. using Windows.Foundation.Collections;  
  8. using Windows.UI.Xaml;  
  9. using Windows.UI.Xaml.Controls;  
  10. using Windows.UI.Xaml.Controls.Primitives;  
  11. using Windows.UI.Xaml.Data;  
  12. using Windows.UI.Xaml.Input;  
  13. using Windows.UI.Xaml.Media;  
  14. using Windows.UI.Xaml.Navigation;  
  15. // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409  
  16. namespace Reverse_Of_Number {  
  17.     /// <summary>  
  18.     /// An empty page that can be used on its own or navigated to within a Frame.  
  19.     /// </summary>  
  20.     public sealed partial class MainPage: Page {  
  21.         public MainPage() {  
  22.             this.InitializeComponent();  
  23.         }  
  24.         private void btncal_Click(object sender, RoutedEventArgs e) {  
  25.             int n = Convert.ToInt32(txtnum.Text);  
  26.             int t, rev = 0;  
  27.             while (n != 0) {  
  28.                 t = n % 10;  
  29.                 rev = rev * 10 + t;  
  30.                 n = n / 10;  
  31.             }  
  32.             txtres.Text = rev.ToString();  
  33.         }  
  34.     }  
  35. }  


And your screen will be displayed like this



Now execute the UWP application, after executing enter the number and your screen will be dispalyed like this



If we enter 0 at last position then the result will be,



In the second case we have entered 0 at the one's place and we have 5 digits but, after finding the reverse number we will get 4 digits.

Because if any number has 0 in front of any number eg., 10 is a number and reverse of this is 01 and we say it is 1. Like in the same way 85670's reverse number is 07658 and we say it is 7658. Now we have successfully created an UWP application that finds the reverse of the entered number.
Ebook Download
View all
Learn
View all