Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

add two numbers in c#

using System;

namespace Add{
	public class Program{

		public static int addition(int a, int b){
			return (a+b);
		}

		public static void Main(){
			int a,b;
			int sum;

			Console.Write("Enter first number: ");
			a = Convert.ToInt32(Console.ReadLine());

			Console.Write("Enter second number: ");
			b = Convert.ToInt32(Console.ReadLine());

			sum = addition(a,b);

			Console.WriteLine("Sum is: " + sum);
		}
	}
}
Comment

c# add two int variables

int a = 1039; 
int b = 7056; 
int newNumber = int.Parse(a.ToString() + b.ToString());
//Or
int newNumber = Convert.ToInt32(string.Format("{0}{1}", a, b));
Comment

C# add two numbers using a method

using System;
public class Program
{
  public static void Main(String[] args)
  {
    int a = 1;
    int b = 2;
    int answer = sum(a,b);//calling the method
    Console.WriteLine(answer);
  }
  //sum is a method
  static int sum(int a,int b) 
  {
    return a+b;
  }
}
Comment

add numbers c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Addition
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int a;
            int b;
            int add;


            Console.WriteLine("Enter Your First Number: "); //allow user input
            a = int.Parse(Console.ReadLine()); //convert to answer (string) to int

            Console.WriteLine("Enter Your Second Number: ");
            b = int.Parse(Console.ReadLine());

            add = a + b; //add the input numbers

            Console.WriteLine(); //blank space
            Console.WriteLine(a + "+" + b + "=" + add); // Print the sum of a + b
            Console.WriteLine(); //blank space
        }
    }
}
Comment

add numbers c#

//c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Program
{
    public class Addition
    {
        public static void Main(string[] args)
        {
           int x = 5; //set value for x
           int y = 6; //set value for y
           int sum; 
            
           sum = x + y; //add the numbers
            
           Console.WriteLine(sum); // Print the sum of x + y
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: stream to byte array c# 
Csharp :: unity Protected 
Csharp :: setup authorize in swagger .net core 
Csharp :: c# int input 
Csharp :: unity C# catch index out or range exception 
Csharp :: c# cast string to double 
Csharp :: cannot convert string to long c# 
Csharp :: C# save pdf stream to file 
Csharp :: delete null elements array c# 
Csharp :: 2d unity point at 
Csharp :: how to get all files from folder and subfolders in c# 
Csharp :: c# replace string case insensitive 
Csharp :: how to access gameobject name 
Csharp :: c# ip address translate localhost 
Csharp :: c# get object property value by name 
Csharp :: c# wpf keyinput DeadCharProcessed 
Csharp :: sort a dictionary by value in c# 
Csharp :: subtract two times c# 
Csharp :: Unity Rotate around the real center 
Csharp :: website link in unity 
Csharp :: c# create datatable 
Csharp :: link nuttom in c# 
Csharp :: get all assemblies c# 
Csharp :: how to open any file on button click in winforms 
Csharp :: .NET Microsoft.dotnet-httprepl 
Csharp :: materials pink in unity 
Csharp :: iactionresult 
Csharp :: c# byte array to string 
Csharp :: get all sundays between two dates c# 
Csharp :: coroutine not eaffected by time.timescale unity 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =