根据从返回的结果和API C#显示文本 [英] C# display text based on a returned result from and API

查看:138
本文介绍了根据从返回的结果和API C#显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ping请求来和API,如果它是成功的返回和OK,如果没有它返回失败。我需要改变的code为平结果显示一些其他的文字,如你的平安是成功的,如果有错,显示你的平安失败我是新来的编程帮助。

 公共部分类API_Menu_Ping:的BasePage
{
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        字符串myCADeveloperKey = ConfigurationManager.AppSettings [CADeveloperKey];
        字符串myCAPassword = ConfigurationManager.AppSettings [CAPassword]​​;        //创建凭据
        ca.api.APICredentials威望=新ca.api.APICredentials();
        cred.DeveloperKey = myCADeveloperKey;
        cred.Password = myCAPassword;        //创建Web服务和附加的凭据
        ca.api.AdminService SVC =新ca.api.AdminService();
        svc.APICredentialsValue = CRED;        //调用该方法        ca.api.APIResultOfString结果= ​​svc.Ping();       PingResult.Text = result.ResultData;      }
    保护无效PingCaApi_Click(对象发件人,EventArgs的发送)
    {    }
}


解决方案

你只是想处理的文字给用户。你只需要一个如果语句:

 如果(result.ResultData ==OK)//或任何一个'是'的结果是
   PingResult.Text =你的平安是成功的;
其他
   PingResult.Text =你的平安失败;

或者你可以用三元运算符缩短:

  PingResult.Text =(result.ResultData ==OK)? 您PING成功:你的平安失败;

I have a ping request to and API and if it is successful it returns and "ok" and if not it returns failure. I need help in changing the the code for the ping result to display some other text like "your ping was successful" and if there was and error to display "your ping failed" I am new to programing.

public partial class API_Menu_Ping : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string myCADeveloperKey = ConfigurationManager.AppSettings["CADeveloperKey"];
        string myCAPassword = ConfigurationManager.AppSettings["CAPassword"];

        //Create credentials
        ca.api.APICredentials cred = new ca.api.APICredentials();
        cred.DeveloperKey = myCADeveloperKey;
        cred.Password = myCAPassword;

        //Create the Web Service and attach the credentials
        ca.api.AdminService svc = new ca.api.AdminService();
        svc.APICredentialsValue = cred;

        //call the method

        ca.api.APIResultOfString result = svc.Ping() ;

       PingResult.Text = result.ResultData ;

      }
    protected void PingCaApi_Click(object sender, EventArgs e)
    {

    }
}

解决方案

you're just wanting to manipulate the text to the user. You just need an if statement:

if(result.ResultData == "ok") //or whatever a 'yes' result is
   PingResult.Text = "Your ping was successful";
else
   PingResult.Text = "Your ping failed";

or you can shorten it with the ternary operator:

PingResult.Text = (result.ResultData == "ok") ? "Your ping was successful" : "Your ping failed";

这篇关于根据从返回的结果和API C#显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆