Có liên quan đến hàm (Funtion) các cao thủ giúp đỡ em ạ.
Em code, thì báo lỗi biến a,b ở dòng lệnh gọi hàm.
Please tell me the error a,b.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Add_Function
{
class Program
{
public static void Main(string[] args)
{
int a;
int b;
int c;
while (true)
{
Console.Write("\n a = ");
string a1=Console.ReadLine();
if (a1.ToUpper() == "EXIT") break;
try
{
a = Convert.ToInt32(a1);
Console.Write(" b = ");
string b1 = Console.ReadLine();
if (b1.ToUpper() == "EXIT") break;
try
{
b = Convert.ToInt32(b1);
}
catch (FormatException)
{
Console.WriteLine(" Please check again ");
}
}
catch (FormatException)
{
Console.WriteLine(" Please check again ");
}
//Console.WriteLine(" => a + b = {0}", c);
Console.WriteLine(" Do you continue or exit ? ");
}
Program prog1 = new Program();
c = Add(a, b);
// => em code, thì báo lỗi biến a,b ở dòng lệnh gọi hàm
//Could you tell me how to use a,b?
// error a, b
//Console.Read();
}//END Main
public static int Add(int x, int y)
{
int result = x + y;
return result;
}//END Add
}//END Program
}

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?