Compiler error · error CS0029

Cannot implicitly convert type 'X' to 'Y'

You put a value of one type into a slot that expects another — and C# can't (or won't) convert it silently. Press Run on the broken code: the error below is produced by the same rules the real compiler uses.

See it happen

int count = "5";   // a string is text, not a number

The compiler is refusing to guess. "5" (with quotes) is a string — two characters, a '5' and nothing about quantity. C# could try to parse it, but a failed guess would be a runtime crash instead of this message, so it stops you at compile time.

The four usual causes (and fixes)

1. string → int: you meant to parse

string input = "5";
int count = int.Parse(input);   // deliberate conversion, may throw FormatException
Console.WriteLine(count + 1);

int.Parse converts, and tells the truth when it can't. If failure is normal (user input!), use int.TryParse(input, out int count) which returns false instead of throwing.

2. number → string: you meant to concatenate

int apples = 3;
string msg = "You have " + apples + " apples";   // + converts via ToString()
Console.WriteLine(msg);

3. bool vs its text form

bool ok = "true"; fails for the same reason. Parse it explicitly:

bool ok = bool.Parse("true");
Console.WriteLine(ok);

4. object of the wrong class

Assigning a Dog to a Car variable is the same error in class form — no conversion exists at all:

class Dog { public string Name; }
class Car { public string Model; }

Dog d = new Dog { Name = "Rex" };
Car c = d;   // CS0029: Cannot implicitly convert type 'Dog' to 'Car'

Frequently asked

What does error CS0029 mean in C#?

CS0029 means you assigned a value of one type to a slot of another type with no implicit conversion — for example int count = "5";. Fix: parse the string with int.Parse(s), build text with .ToString() or $"…" interpolation for the reverse direction, and use an explicit (int) cast for double→int (that case is CS0266).

What is the difference between CS0029 and CS0266?

CS0029 means no implicit conversion exists at all (string to int) — you must parse or convert deliberately. CS0266 means a conversion exists but would lose data (double to int), so the compiler requires you to write the explicit cast, like (int)price.

Related: CS0266 (the "missing cast" sibling)

If the types are convertible but only explicitly — the classic case is double → int, which loses the fraction — you get CS0266 instead, with the hint "An explicit conversion exists (are you missing a cast?)":

double price = 9.99;
int rounded = price;        // CS0266: would silently lose the .99
double price = 9.99;
int rounded = (int)price;   // explicit cast: "I know, truncate it"
Console.WriteLine(rounded);

Rule of thumb: CS0029 = no implicit conversion exists (parse, concatenate, or rethink); CS0266 = a cast exists but you must write it, accepting the loss.

Checklist