❤❤前往 陳間時光 賣場❤❤

2019年8月28日 星期三

LinQ 基本用法 (C# Unity)




using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class LinqTest1 : MonoBehaviour
{
    List<BubbleTea> bubbleTea = new List<BubbleTea> {
            new BubbleTea(70,"大"),
            new BubbleTea(60,"中"),
            new BubbleTea(50,"小"),
            new BubbleTea(40,"大"),
            new BubbleTea(30,"中"),
            new BubbleTea(20,"小"),
            new BubbleTea(80,"大"),
            new BubbleTea(60,"大"),
            new BubbleTea(50,"小"),
            new BubbleTea(40,"小"),
            new BubbleTea(30,"小"),
        };

    void Start()
    {
                //查詢甜度大於40的大杯紅茶 且依照甜度排序
        var result = //福大師 從哪裡開始選擇
                     from tea in bubbleTea
                     where tea.sweetDegree > 40&&tea.size=="大"
                     orderby tea.sweetDegree
                     select tea;


        foreach (var tea in result)
        {
            Debug.Log(tea.sweetDegree + tea.size);
        }
    }
 }

/*
  http://www.morningfungame.com/
*/

public class BubbleTea //泡沫紅茶
{
    public int sweetDegree;//甜度
    public string size;//大小
    public BubbleTea(int sweetDegree, string size)
    {
        this.sweetDegree = sweetDegree;
        this.size = size;
    }
}

沒有留言:

張貼留言

留言給作者加油打氣

C# 與 Unity 免費中文教學影片推薦

C# 與 Unity 免費中文教學影片推薦
.

超多遊戲資源下載 包山包海