我是.net核心的新手,我正在尝试构建一个计算器Web API.我努力寻找确切的方法来做到这一点.我设法用多个get方法构建API控制器部分,返回数学运算.下面是代码
//MathController.cs file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace Calculationwebapi.Controllers
{
public class MathController : ApiController
{
[HttpGet]
public int Add(int value1, int value2)
{
return value1 + value2;
}
[HttpGet]
public int Substract(int value1, int value2)
{
return value1 - value2;
}
[HttpGet]
public int Multiply(int value1, int value2)
{
return value1 * value2;
}
[HttpGet]
public int Divide(int value1, int value2)
{
return value1 / value2;
}
[HttpGet]
public string …Run Code Online (Sandbox Code Playgroud) .net asp.net-core-mvc .net-core asp.net-core asp.net-core-webapi
我正在尝试使用 .net core web api 构建一个简单的 web api,它将执行基本的数学运算。我编写了由多个 get 方法组成的控制器部分,当它被调用时,它返回执行操作的值。控制器代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Calculation.Controllers
{
[Route("api/[controller]")]
public class MathController : Controller
{
[HttpGet("Add")]
public int Add(int value1, int value2)
{
return value1 + value2;
}
[HttpGet("Subtract")]
public int Substract(int value1, int value2)
{
return value1 - value2;
}
[HttpGet("Multiply")]
public int Multiply(int value1, int value2)
{
return value1 * value2;
}
[HttpGet("Division")]
public int Division(int value1, int value2)
{
return value1 / …Run Code Online (Sandbox Code Playgroud)