© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
morry329#

✅ Cannot implicit convert type

I am working on this LC puzzle https://leetcode.com/problems/binary-tree-level-order-traversal/?envType=study-plan&id=level-1
Here's my progress:
public IList<IList<int>> LevelOrder(TreeNode root) {
        List<int> result = new List<int>();
        if(root == null){
            return result;
        }

        Queue<TreeNode> queue = new LinkedList<TreeNode>(); //ERROR HERE
        queue.Enqueue(root);
        while(queue != null){
            int size = queue.Count();
            List<int> curr = new List<int>();
            for(int i = 0; i < size; i++){
                TreeNode node = queue.Dequeue();
                curr.Add(node.val);
            }
            curr = result;
        }
        return result;
    }
public IList<IList<int>> LevelOrder(TreeNode root) {
        List<int> result = new List<int>();
        if(root == null){
            return result;
        }

        Queue<TreeNode> queue = new LinkedList<TreeNode>(); //ERROR HERE
        queue.Enqueue(root);
        while(queue != null){
            int size = queue.Count();
            List<int> curr = new List<int>();
            for(int i = 0; i < size; i++){
                TreeNode node = queue.Dequeue();
                curr.Add(node.val);
            }
            curr = result;
        }
        return result;
    }
`

I am getting the error Cannot implicitly convert type 'System.Collections.Generic.LinkedList<TreeNode>' to 'System.Collections.Generic.Queue<TreeNode>' (see the ERROR HERE in the code). Could anyone kindly tell me why?
LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
LeetCode - The World's Leading Online Programming Learning Platform
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
Convert enclosing type - implicit enum conversion
C#CC# / help
2y ago
✅ Cannot convert from anonymous type
C#CC# / help
4y ago