How to append int to int in C#

4 Answers

0 votes
using System;

class Program
{
    static void Main() {
        int a = 10; 
        int b = 938; 
        
        int newNumber = int.Parse(a.ToString() + b.ToString());

        Console.WriteLine(newNumber);
    }
}
   
   
   
   
/*
run:
      
10938
    
*/

 



answered Oct 18, 2023 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        int a = 10; 
        int b = 938; 
        
        int newNumber = Convert.ToInt32(string.Format("{0}{1}", a, b));

        Console.WriteLine(newNumber);
    }
}
   
   
   
   
/*
run:
      
10938
    
*/

 



answered Oct 18, 2023 by avibootz
0 votes
using System;
 
class Program
{
    static void Main() {
        int a = 10; 
        int b = 938; 
         
        a = int.Parse(a.ToString() + b.ToString());
 
        Console.WriteLine(a);
    }
}
    
    
    
    
/*
run:
       
10938
     
*/

 



answered Oct 19, 2023 by avibootz
0 votes
using System;
 
class Program
{
    int concatenate(int x, int y) {
        int pow = 10;
        
        while(y >= pow)
            pow *= 10;
            
        return x * pow + y;        
    }
    static void Main() {
        int a = 10; 
        int b = 938; 
         
        a = int.Parse(a.ToString() + b.ToString());
 
        Console.WriteLine(a);
    }
}
    
    
    
    
/*
run:
       
10938
     
*/

 



answered Oct 19, 2023 by avibootz

Related questions

1 answer 230 views
1 answer 297 views
1 answer 302 views
1 answer 295 views
295 views asked Apr 26, 2017 by avibootz
1 answer 267 views
1 answer 247 views
247 views asked Jan 16, 2017 by avibootz
1 answer 279 views
279 views asked Jan 16, 2017 by avibootz
...