【发布时间】:2016-05-23 22:46:04
【问题描述】:
嘿,我想弄清楚如何从 ServiceController 访问变量:ApiController 像这样:
namespace WebApi.App.Controllers
{
public class ServiceController : ApiController
{
string outputFile = "F:\\debugData\\debug.txt";
public bool isDebuging = false;
...etc etc
我想要获得的是 isDebuging 值,但在我的 Class 文件 中:
namespace WebApi.App.Models
{
public class checkEnviroment
{
public string checkEnviroment()
{
WebApi.App.Controllers.ServiceController["isDebuging"] = true;
etc etc...
这可能吗?为了从 ServiceController : ApiController 获取或设置值,我似乎找不到正确的语法。
任何帮助都会很棒!
【问题讨论】:
-
确保代码不会远程工作 :) 您在哪里/如何设置
isDebugging? -
@ClaudioRedi 只是普通的 isDebugging = false; 如果我在 ServiceController : ApiController 类中,它工作得很好。但是,一旦我在另一个创建的类文件中并尝试引用该公共变量,那么这就是我想做的事情。
-
阅读更多关于如何在 C# 中创建类实例dotnetperls.com/new
-
啊,@Regfor。谢谢!随意将其作为官方答案。
标签: c# variables asp.net-web-api asp.net-web-api2 public-method