Full-Stack freelance Umbraco developer in the UK.

George Phillipson - Freelance Umbraco developer

C Sharp Tuple Return Multiple Values

Returning Multiple Values Using Tuples In C#
Intellisense in visual studio
using System.Collections.Generic;

namespace Web.Helper.TuplesHelper
{
    public class MyDogList
    {
        public IEnumerable<string> DogList()
        {
            List<string> dogs = new List<string> { "German Shepherd", "Siberian Husky", "Bernese Mountain Dog" };

            return dogs;
        }

        public string TestString    = "My favourite dogs is a : ";
        public bool ItsTrue         = true;
    }
}
using System.Collections.Generic;

namespace Web.Model.TuplesViewModel
{
    public class TuplesViewModel
    {
        public string TestString                    { get; set; }
        public IEnumerable<string> ListOfDogs       { get; set; }
        public bool IsItTrue                        { get; set; }
    }
}
using System.Linq;
using System.Web.Mvc;
using Web.Helper.TuplesHelper;
using Web.Model.TuplesViewModel;

namespace Web.UI.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var tupleValue = new MyDogList();

            var model = new TuplesViewModel
            {
                TestString  = tupleValue.TestString,
                ListOfDogs  = tupleValue.DogList().Where(x=>x.Contains("German Shepherd")),
                IsItTrue    = tupleValue.ItsTrue
            };
            return View(model);
        }
    }
}
@model Web.Model.TuplesViewModel.TuplesViewModel
@{
    ViewBag.Title = "Home Page";
}

<p>@Model.TestString</p>
<ul>
    @foreach (var data in Model.ListOfDogs)
    {
        <li>@data</li>
    }
</ul>
<p>It is @Model.IsItTrue</p>
Results for test code

Please enter your comment.