简体   繁体   中英

C# How to remove char from LinkedList of chars to a char variable?

Following code results with error:

Cannot implicitly convert type 'void' to 'char'

    string S = "Hello World!";        
    LinkedList<char> myChars = new LinkedList<char>();

    foreach (char ch in S)
    {
        myChars.AddFirst(ch);
    }

    char c = myChars.RemoveFirst();

How can I remove first element and copy it to a char variable c?

Thank you!

You can do it like this:

var node = myChars.First;
char c = node.Value;
myChars.Remove(node);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM