小编Sco*_*ott的帖子

嵌套if ... else流的更简单/更有效的方法?

我正在为一个基于Flash客户端的游戏开发仿真服务器,它有一个"宠物系统",我想知道是否有更简单的方法来检查指定宠物的等级.

当前代码:

public int Level
{
    get
    {
        if (Expirience > 100) // Level 2
        {
            if (Expirience > 200) // Level 3
            {
                if (Expirience > 400) // Level 4 - Unsure of Goal
                {
                    if (Expirience > 600) // Level 5 - Unsure of Goal
                    {
                        if (Expirience > 1000) // Level 6
                        {
                            if (Expirience > 1300) // Level 7
                            {
                                if (Expirience > 1800) // Level 8
                                {
                                    if (Expirience > 2400) // Level 9
                                    { …
Run Code Online (Sandbox Code Playgroud)

.net c#

6
推荐指数
2
解决办法
627
查看次数

.NET Regex模式?

var flashvars = {
        "client.allow.cross.domain" : "0", 
        "client.notify.cross.domain" : "1",
};
Run Code Online (Sandbox Code Playgroud)

由于某些奇怪的原因,不希望使用此代码进行解析(在C#中).

private void parseVariables() {
       String page;
       Regex flashVars = new Regex("var flashvars = {(.*?)}", RegexOptions.Multiline | RegexOptions.IgnoreCase);
       Regex var = new Regex(@"""(.*?)"",", RegexOptions.Multiline | RegexOptions.IgnoreCase);
       Match flashVarsMatch;
       MatchCollection matches;
       String vars = "";

       if (!IsLoggedIn)
       {
            throw new NotLoggedInException();
       }

       page = Request(URL_CLIENT);

       flashVarsMatch = flashVars.Match(page);

       matches = var.Matches(flashVarsMatch.Groups[1].Value);

       if (matches.Count > 0)
       {
         foreach (Match item in matches)
         {
            vars += item.Groups[1].Value.Replace("\" : \"", "=") …
Run Code Online (Sandbox Code Playgroud)

.net c# regex

3
推荐指数
1
解决办法
1983
查看次数

标签 统计

.net ×2

c# ×2

regex ×1