C# Split String (Argument Type ‘string’ Is Not Assignable to ‘char’)

This stupid one has got me a few times. You try to use split the way everyone else appears to be using it in all the examples out there but you get this error:

Argument type ‘string’ is not assignable to parameter type ‘char’

The answer is simple: use single quotes.

So don’t do this:

Do this:

Why is this? To quote the accepted answer on this Stackoverflow question:

Single quotes encode a single character (data type char), while double quotes encode a string of multiple characters.

Split() wants a char and using single quotes gives it what it wants.

Creating your first programming language is easier than you think.

Understanding how a programming language works is a surefire way to be a better developer. Read more.

Suggested Reading

written by Ryan Bosinger
Ryan is a web developer living and working in Banff Alberta. He also writes for giftsforpeoplewitheverything.com and freefoley.com.

One Response to “C# Split String (Argument Type ‘string’ Is Not Assignable to ‘char’)”

  1. John says:

    Oh. My. God.

    I’m an idiot.

Leave a Reply