© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
Endermanbugzjfc

❔ Compiler cannot infer lambda return type

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Cysharp.Threading.Tasks;

public class Title : MonoBehaviour
{
    void Start() {
        StartCoroutine(ShowTitles());
    }

    IEnumerator ShowTitles() {
        string[] words = {"The", "White", "Christmas", "welcomes", "you!"};
        foreach (var pack in words.Select((word) => {
            var obj = GameObject.Find(word);
            var render = obj.GetComponent<MeshRenderer>();
            Material mat = render.materials[0];

            var colour = mat.GetColor("_Color");
            float H, S, V;
            Color.RGBToHSV(colour, out H, out S, out V);
            mat.SetColor("_Color", Color.HSVToRGB(H, S, 1));

            return new {mat, H, S, V};
        })) {
            int x = 10;
            for (int i=0; i < x; i++) {
                yield return new WaitForSeconds(0.1f);

                pack.mat.SetColor("_Color", Color.HSVToRGB(pack.H, pack.S, pack.V / (float)x));
            }
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Cysharp.Threading.Tasks;

public class Title : MonoBehaviour
{
    void Start() {
        StartCoroutine(ShowTitles());
    }

    IEnumerator ShowTitles() {
        string[] words = {"The", "White", "Christmas", "welcomes", "you!"};
        foreach (var pack in words.Select((word) => {
            var obj = GameObject.Find(word);
            var render = obj.GetComponent<MeshRenderer>();
            Material mat = render.materials[0];

            var colour = mat.GetColor("_Color");
            float H, S, V;
            Color.RGBToHSV(colour, out H, out S, out V);
            mat.SetColor("_Color", Color.HSVToRGB(H, S, 1));

            return new {mat, H, S, V};
        })) {
            int x = 10;
            for (int i=0; i < x; i++) {
                yield return new WaitForSeconds(0.1f);

                pack.mat.SetColor("_Color", Color.HSVToRGB(pack.H, pack.S, pack.V / (float)x));
            }
        }
    }
}

\Avatar\Title.cs(25,20): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
\Avatar\Title.cs(25,20): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

cannot convert from 'TypeA' to 'TypeB' with generics
C#CC# / help
2y ago
assure compiler type is not null
C#CC# / help
2y ago
❔ Cannot convert lambda expression to type 'Activity' because it is not a delegate type error
C#CC# / help
3y ago
✅ Covariant return type properties
C#CC# / help
2y ago