当前位置: 首页>>代码示例>>C#>>正文


C# Tuple类代码示例

本文整理汇总了C#中Tuple的典型用法代码示例。如果您正苦于以下问题:C# Tuple类的具体用法?C# Tuple怎么用?C# Tuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Tuple类属于命名空间,在下文中一共展示了Tuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddToMenu

        public static void AddToMenu(Menu menu,
            string uniqueId,
            HealthCheckType checkType,
            HealthValueType valueType,
            string prefix = null,
            int value = 30,
            int minValue = 0,
            int maxValue = 100)
        {
            try
            {
                if (Menues.ContainsKey(uniqueId))
                {
                    throw new ArgumentException(
                        string.Format("HealthHealthger: UniqueID \"{0}\" already exist.", uniqueId));
                }

                menu.AddItem(
                    new MenuItem(
                        menu.Name + ".health-" + uniqueId,
                        (!string.IsNullOrEmpty(prefix) ? prefix + " " : string.Empty) +
                        (checkType == HealthCheckType.Minimum ? "Min. Health" : "Max. Health") +
                        (valueType == HealthValueType.Percent ? " %" : string.Empty)).SetValue(
                            new Slider(value, minValue, maxValue)));

                Menues[uniqueId] = new Tuple<Menu, HealthCheckType, HealthValueType>(menu, checkType, valueType);
            }
            catch (Exception ex)
            {
                Global.Logger.AddItem(new LogItem(ex));
            }
        }
开发者ID:fgpmaia123,项目名称:LeagueSharp-Standalones,代码行数:32,代码来源:HealthManager.cs

示例2: IntegerAverageOnTwoTuple

 public void IntegerAverageOnTwoTuple()
 {
     var sut = new Tuple<int, int>(1, 2);
       double expected = sut.AsEnumerable().Cast<int>().Average();
       double actual = sut.Average(x => (int) x);
       Assert.AreEqual(expected, actual);
 }
开发者ID:nicenemo,项目名称:Noaber,代码行数:7,代码来源:TupleAverageTests.Integer.cs

示例3: InsertSeparator

        private static void InsertSeparator(Tuple<ICommandItem, Menu> previous, Tuple<ICommandItem, Menu> current)
        {
            // Get lineage of each
            IMenu[] previousLineage = previous.Item2.Lineage().Reverse<IMenu>().ToArray<IMenu>();
            IMenu[] currentLineage = current.Item2.Lineage().Reverse<IMenu>().ToArray<IMenu>();

            // Find lowest common ancestor
            // (Assumes common ancestor exists)
            int minLength = Math.Min(previousLineage.Length, currentLineage.Length);

            IMenuItem insertBefore = null;
            IList<IMenuItem> collection = null;
        
            for (int i = 0; i < minLength; i++)
            {
                if (previousLineage[i] != currentLineage[i])
                {
                    insertBefore = currentLineage[i];
                    collection = ((Menu)currentLineage[i - 1]).ChildCollection;
                }
            }

            if (insertBefore == null)
            {
                insertBefore = minLength < currentLineage.Length ? currentLineage[minLength] as IMenuItem
                    : current.Item1;
                collection = ((Menu)currentLineage[minLength - 1]).ChildCollection;
            }

            int idx = collection.IndexOf(insertBefore);
            System.Diagnostics.Debug.Assert(idx >= 0);
            collection.Insert(idx, new Separator());
        }
开发者ID:vincenthamm,项目名称:ATF,代码行数:33,代码来源:MenuUtil.cs

示例4: Main

        static void Main(string[] args)
        {
            Tuple<string, int>[] tuples = new Tuple<string, int>[] {
                new Tuple<string, int>("a", 3),
                new Tuple<string, int>("b", 2),
                new Tuple<string, int>("b", 5) };

            MapReduce<string, int> letters = new MapReduce<string, int>(tuples);
            IEnumerable<Tuple<string, int>> newmap;

            letters.Map<string, int>((input) =>
                {
                    return new Tuple<string, int>[] { new Tuple<string, int>(input.Item1, input.Item2 * input.Item2) };
                }, out newmap);

            IEnumerable<Tuple<string, int>> reduction = letters.Reduce<string, int>(newmap, (key, values) =>
                {
                    int total = 0;
                    foreach (var item in values)
                    {
                        total += item;
                    }
                    return total;
                });

            foreach (var item in reduction)
            {
                Console.WriteLine("{0} = {1}", item.Item1, item.Item2);
            }

            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
开发者ID:NelsonBilber,项目名称:programming-languages,代码行数:33,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();
            Tuple<uint, BigInteger> max = new Tuple<uint, BigInteger>(0, 0);
            for (uint i = 2; i <= 1000; i++)
            {
                if ((uint)Math.Sqrt(i) != Math.Sqrt(i))
                {
                    BigInteger xSolution = getMinimumSolution((int)i);
                    if (xSolution > max.Item2)
                    {
                        max = new Tuple<uint, BigInteger>(i, xSolution);
                    }
                  //  Console.WriteLine(i + " => " + xSolution);
                }
                
            }

            Console.WriteLine("Answer = " + max.Item1 + " => " + max.Item2);
            Console.WriteLine("DONE in " + sw.ElapsedMilliseconds + " s" );
                Console.ReadKey();
            

         

        }
开发者ID:theblindspring,项目名称:PEuler,代码行数:26,代码来源:Program.cs

示例6: AddExtension

        private static bool AddExtension( XElement extensions, Func<string, bool> resolveOption, Tuple<string, string, Func<XElement>> mapping )
        {
            Contract.Requires( extensions != null );
            Contract.Requires( resolveOption != null );
            Contract.Requires( mapping != null );

            var option = mapping.Item1;

            // the option is not enabled
            if ( !resolveOption( option ) )
                return false;

            var category = mapping.Item2;

            // the extension is already configured
            if ( extensions.Elements( ExtensionName ).Any( e => ( (string) e.Attribute( "Category" ) ) == category ) )
                return false;

            // create and add extension
            var factory = mapping.Item3;
            var extension = factory();

            extensions.Add( extension );
            return true;
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:25,代码来源:ManifestExtensionWriter.cs

示例7: ItemsWithConflictingHighestScoreException

 public ItemsWithConflictingHighestScoreException(Tuple<IValueProvider, IProbe>[] itemsWithConflictingScore, int highestScore)
     : base(string.Format(
         "items: {0} with conflicting highest score of {1} exists, cannot determine default", string.Concat(itemsWithConflictingScore.Select(x=>x.Item1.ToString())), highestScore))
 {
     ItemsWithConflictingScore = itemsWithConflictingScore;
     HighestScore = highestScore;
 }
开发者ID:Tetnacious,项目名称:ByContext,代码行数:7,代码来源:ItemsWithConflictingHighestScoreException.cs

示例8: Update

        public override void Update(object sender, Tuple<Sale, SaleState> item)
        {
            using (SalesDBEntities context = new SalesDBEntities())
            {
                Product product = context.Products
                    .Where(p => p.ProductID == item.Item1.ProductID)
                    .SingleOrDefault<Product>();

                switch (item.Item2)
                {
                    case SaleState.SALE_ADD:
                        product.TotalSalesAmount += item.Item1.Quantity;
                        break;
                    case SaleState.SALE_UPDATE:
                        product.TotalSalesAmount = item.Item1.Quantity;
                        break;
                    case SaleState.SALE_DELETE:
                        product.TotalSalesAmount -= item.Item1.Quantity;
                        break;
                    default:
                        break;
                }   
                context.SaveChanges();
            }
        }
开发者ID:stijnmoreels,项目名称:nmct.own.observer,代码行数:25,代码来源:ProductObserver.cs

示例9: GetPostByCategory

        public ActionResult GetPostByCategory(int id,int ?page)
        {
            _pagingHandler.PageIndex = page ?? 1;
            var postList = _pagingHandler.GetPagingList(c=>c.CategoryId==id,c => new PostModel()
            {
                Title = c.Title,
                DateTime = c.DateTime,
                ShortDescription = c.ShortDescription,
                FullName = c.User.FirstName + " " + c.User.LastName,
                Id = c.Id
            }, c => c.DateTime, ListSortDirection.Descending).ToList();

            var pagingModel = new PagingModel()
            {
                HasNextPage = _pagingHandler.HasNextPage,
                HasPreviousPage = _pagingHandler.HasPreviousPage,
                PageIndex = _pagingHandler.PageIndex,
                IsFirstPage = _pagingHandler.IsFirstPage,
                IsLastPage = _pagingHandler.IsLastPage,
                PageCount = _pagingHandler.PageCount,
                PageNumber = _pagingHandler.PageNumber,
                PageSize = _pagingHandler.PageSize
            };

            var model = new Tuple<List<PostModel>, PagingModel>(postList, pagingModel);
            return View("_ListPost", model);
        }
开发者ID:cuongtranba,项目名称:PersonalBlog,代码行数:27,代码来源:CategoryController.cs

示例10: readPriceList

        static public List<Tuple<String, double>> readPriceList()
        {
            List<Tuple<String, double>> priceList = new List<Tuple<String, double>>();

            try
            {
                string[] lines = System.IO.File.ReadAllLines("PriceData.txt");

                foreach (String line in lines)
                {
                    String[] split_string = line.Split('[');
                    split_string[1] = split_string[1].Trim(']');
                    Tuple<String, double> pair = new Tuple<String, double>(split_string[0], Convert.ToDouble(split_string[1]));
                    priceList.Add(pair);
                }
            }

            // This can catch either a file not found exception, or a format exception for the double conversion
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            return priceList;
        }
开发者ID:MitchellHansen,项目名称:WorkOrderGenerator,代码行数:25,代码来源:DataInterfacer.cs

示例11: Draw

        public void Draw(SpriteBatch sbatch)
        {
            for (int i = 0; i < size + 1; i++)
            {

                Tuple<Vector2, Vector2> line4 = new Tuple<Vector2, Vector2>(gridEdgeCoords(new Vector2(i, 0)), gridEdgeCoords(new Vector2(i, size))); //CartesianCoords(new Vector2(x, 0)), CartesianCoords(new Vector2(x, (float) rows-1))

                float angle4 = (float)Math.Atan2(line4.Item2.Y - line4.Item1.Y, line4.Item2.X - line4.Item1.X);
                float length4 = Vector2.Distance(line4.Item1, line4.Item2);

                sbatch.Draw(blank, line4.Item1 + new Vector2(0, 0), null, Microsoft.Xna.Framework.Color.Red, angle4, Vector2.Zero, new Vector2(length4, 1.0f), SpriteEffects.None, 0.49f);

            }

            for (int j = 0; j < size + 1; j++)
            {
                Tuple<Vector2, Vector2> line4 = new Tuple<Vector2, Vector2>(gridEdgeCoords(new Vector2(0, j)), gridEdgeCoords(new Vector2(size, j))); //CartesianCoords(new Vector2(x, 0)), CartesianCoords(new Vector2(x, (float) rows-1))

                float angle4 = (float)Math.Atan2(line4.Item2.Y - line4.Item1.Y, line4.Item2.X - line4.Item1.X);
                float length4 = Vector2.Distance(line4.Item1, line4.Item2);

                sbatch.Draw(blank, line4.Item1 + new Vector2(0, 0), null, Microsoft.Xna.Framework.Color.Red, angle4, Vector2.Zero, new Vector2(length4, 1.0f), SpriteEffects.None, 0.49f);

            }
        }
开发者ID:samconnolly,项目名称:Multiverse,代码行数:25,代码来源:CityIsogrid.cs

示例12: FormatLine

 public string FormatLine(int id, Tuple<float, float, float> xyz, Tuple<int, int, int> rgb)
 {
     return String.Format(CultureInfo.InvariantCulture,
         "{0} {1} {2} {3} {4} {5}\n",
         xyz.Item1, xyz.Item2, xyz.Item3,
         rgb.Item1, rgb.Item2, rgb.Item3);
 }
开发者ID:guilhermeRey,项目名称:ime-visiongroup,代码行数:7,代码来源:Ply.cs

示例13: Bank

 /// <summary>
 /// Ctor is based on single line from the fed's text report
 /// </summary>
 /// <param name="li"></param>
 internal Bank(dynamic li)
 {
     const string COMMA = ",";
     const string LETTER_Y = "Y";
     UpsertName(KindsOfNames.Legal, li.BankName);
     UpsertName(KindsOfNames.Abbrev, li.BankName);
     Rssd = new ResearchStatisticsSupervisionDiscount { Value = li.BankId };
     UsCityStateZip cityOut;
     if (UsCityStateZip.TryParse(li.Location, out cityOut))
         BusinessAddress = new Tuple<UsStreetPo, UsCityStateZip>(null, cityOut);
     if (FedLrgBnk.TypeOfBankAbbrev3Enum.ContainsKey(li.Chtr))
         BankType = FedLrgBnk.TypeOfBankAbbrev3Enum[li.Chtr];
     var assets = new FinancialAssets { Src = FedLrgBnk.RELEASE_URL };
     decimal conAssts = 0;
     decimal domAssts = 0;
     if (decimal.TryParse(li.ConsolAssets.Replace(COMMA, string.Empty), out conAssts))
         assets.TotalAssets = new Pecuniam(conAssts * ONE_THOUSAND);
     if (decimal.TryParse(li.DomesticAssets.Replace(COMMA, string.Empty), out domAssts))
         assets.DomesticAssets = new Pecuniam(domAssts * ONE_THOUSAND);
     int domBranches = 0;
     int frnBranches = 0;
     int pfo = 0;
     if (int.TryParse(li.NumOfDomBranches.Replace(COMMA, string.Empty), out domBranches))
         assets.DomesticBranches = domBranches;
     if (int.TryParse(li.NumOfFgnBranches.Replace(COMMA, string.Empty), out frnBranches))
         assets.ForeignBranches = frnBranches;
     IsInternational = li.Ibf == LETTER_Y;
     if (int.TryParse(li.PercentFgnOwned, out pfo))
         assets.PercentForeignOwned = Math.Round((double)pfo / 100, 2);
     Assets = new Dictionary<DateTime, FinancialAssets> { { li.RptDate, assets } };
 }
开发者ID:nofuture-git,项目名称:31g,代码行数:35,代码来源:FinancialFirm.cs

示例14: Distance

 static double Distance(Tuple<int, int> coords1, Tuple<int, int> coords2)
 {
     return Math.Sqrt(
         (coords1.Item1 - coords2.Item1) * (coords1.Item1 - coords2.Item1) +
         (coords1.Item2 - coords2.Item2) * (coords1.Item2 - coords2.Item2)
     );
 }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:7,代码来源:Program.cs

示例15: Index

        //
        // GET: /Home/
        public ActionResult Index(string sortOrder, int? page)
        {
            ViewBag.DateSortParm = string.IsNullOrEmpty(sortOrder) ? "date_desc" : "";
            ViewBag.CostSortParm = sortOrder == "Cost" ? "cost_desc" : "Cost";

            var products = WebApiHelper.GetProductsFromServer("api/product/all", Method.GET);

            switch (sortOrder)
            {
                case "date_desc":
                    products = products.OrderBy(s => s.Id).ToList();
                    break;
                case "Cost":
                    products = products.OrderBy(s => s.Price).ToList();
                    break;
                case "cost_desc":
                    products = products.OrderByDescending(s => s.Price).ToList();
                    break;
                default:
                    products = products.OrderByDescending(s => s.Id).ToList();
                    break;
            }

            int pageSize = 10;
            int pageNumber = (page ?? 1);

            IPagedList<DataTransferLayer.Products.Product> pl = products.ToPagedList(pageNumber, pageSize);

            var a = new Tuple<IPagedList<DataTransferLayer.Products.Product>, string>(pl, "");

            return View(a);
        }
开发者ID:loiluongit,项目名称:TraoDoiDoCu_API,代码行数:34,代码来源:HomeController.cs


注:本文中的Tuple类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。