C# 提示当前上下文中不存在名称Dcommission

落伍的鱼 2017-02-16 11:21:37
新手学习中,在money(string pid, int mall = 0)中引用double sdx(string pid)返回的值,提示当前上下文中不存在名称Dcommission,private string Dcommission; 定义之后并没有返回 key 。请帮忙看看是不是哪里写错了。

public string money(string pid, int mall = 0)
{
try
{
string url = Utility.FormatUrl(Resources.GyTbUrl).Replace("{pid}", pid);
if (mall == 1)
{
url = Utility.FormatUrl(Resources.GyTmUrl).Replace("{pid}", pid);
}
string jsondata = http.GetU(url);
string AuctionId = Utility.Get_Middle_Text(jsondata, "\"auctionId\":", ",");//商品ID

if (tkSpecialCampaignIdRateMap.Trim() != "null")
{
double Dcommission = sdx(pid); //返回比例
}
///提示当前上下文中不存在名称Dcommission
return "{\"auctionId\":\"" + AuctionId + "\",\"Dcommission\":\"" + Dcommission + "\"}";
}
catch (Exception ex)
{
return ex.ToString();
}
}

public double sdx(string pid)
{
try
{
string DxData = http.GetU(Utility.FormatUrl(Resources.DingxList).Replace("{pid}", pid));
int key = 0;
string CampaignID = null;
string ShopKeeperID = null;
Regex regex = new Regex(@"""commissionRate"":(.*?),""CampaignID"":(.*?),.*?""Exist"":(.*?),""manualAudit"":(.*?),""ShopKeeperID"":(.*?),");
if (regex.IsMatch(DxData))
{
MatchCollection matchCollection = regex.Matches(DxData);
foreach (Match match in matchCollection)
{
if (match.Groups[3].Value == "true")
{
runlog("PID:" + pid + " 已申请过");
key = Convert.ToInt32(Convert.ToDouble(match.Groups[1].Value.Trim()));
}
if (match.Groups[4].Value != "1") //排除手动审核
{
if (Convert.ToInt32(Convert.ToDouble(match.Groups[1].Value.Trim())) > key)
{
key = Convert.ToInt32(Convert.ToDouble(match.Groups[1].Value.Trim()));
CampaignID = match.Groups[2].Value;
ShopKeeperID = match.Groups[5].Value;
}
}
}
}
if (CampaignID == null) return 0;
string postDXstatus = http.GetU(Resources.postDX, Utility.FormatUrl(Resources.postDXdata).Replace("{CampaignID}", CampaignID).Replace("{ShopKeeperID}", ShopKeeperID).Replace("{applyreason}", applyreason));
if (postDXstatus.Contains("\"ok\":true"))
{
runlog("PID:" + pid + " 申请成功!");
return key;
}
else
{
runlog("PID:" + pid + " 申请失败" + postDXstatus);
return 0;
}
}
catch
{
return 0;
}
}
...全文
243 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
落伍的鱼 2017-02-16
  • 打赏
  • 举报
回复
谢谢了。。跑错地方了
yes-hyh 2017-02-16
  • 打赏
  • 举报
回复
你的Dcommission定义在if里面,所以它的的作用域只在if里面,改成下面这样

 double Dcommission = 0.0;
if (tkSpecialCampaignIdRateMap.Trim() != "null")
{
          Dcommission = sdx(pid); //返回比例
}
还有,C#的问题最好到C#板块去问

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧