csharp Advanced Exercises: a list of objects in the form of equation [Difficulty: Level 2] - view the C # programming classic exam, exercises of varying difficulty C #, C # novice suitable for self-study of advanced training

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_45444821/article/details/100587339

Advanced title csharp practice: the list of objects in the form of equation [Difficulty: Level 2]:

Your task is to write a list of objects on extension methods ** ** and returns an integer to solve the equation.
List includes integers and strings, and Null.

List the following format:

[Image dump outer link failure (img-KIDvdgpe-1567778231976) (http://crowd-multilogue.com/Images/Codewars/KataPic.png "Logo Title Text 1")]

List  objectList = new List (){2," - ",82,"+",802,"+",62," - ",23," - ",924,"+", 1,"+",200,"+",null,"+",102,"+",300," - ",10,"=",924};

null is a red box, you have to find an integer to solve the equation.
Digital is an integer, the operator ( "+", "-", "=") is a string.

Programming objectives:

namespace BlankExtention {
using System;
using System.Collections.Generic;
using System.Linq;
  public static class Kata
    {
        public static int CalculateBlank(this List objectList)
        {
            //Happy Coding
        }
    }
}


Test sample:

namespace BlankExtention {
  using NUnit.Framework;
  using System.Collections.Generic;
  using System.Linq;
  using System;
  [TestFixture]
    public class MyTest
    {
        {
            List objectList = new List() { 2, "-", 82, "+", 802, "+", 62, "-", 23, "-", 924, "+", 1, "+", 200, "+", null, "+", 102, "+", 300, "-", 10, "=", 924 };
            Assert.AreEqual(494,objectList.CalculateBlank());
        }
        [Test]
        public void SecondTest()


Best answer (multiple solutions):

Click to view answer

More related topics:

Disclaimer

This blog All programming topics and answers were collected from the Internet, users are mainly used for study and reference, if any violation of your rights, please contact the administrator to delete, thank
entitled to collect https://www.codewars.com/
HTTPS: / /www.codewars.com/kata/equation-in-form-of-objects-list

Guess you like

Origin blog.csdn.net/weixin_45444821/article/details/100587339