The problem could be down to many different things & I would always recommend a check on a diagnostic tool such as Mercedes STAR to see if any fault codes are stored.
A common problem however can be a failing crankshaft position sensor - this is fairly cheap & easy to replace. It often fails without storing any fault codes so if no codes are stored then it may be worth replacing this next.
It also often causes intermittent starting problems usually when hot - when left to cool down it will start up as if nothing was wrong!
Best regards, Paul