@numan43 Its to do with the weight/water.
If you were to take that raw onion in your example above, and cook it in 3 different ways and then eat it (the whole onion) you'd still have the same amount of carbs no matter what way you cooked it (because you'd be eating the whole onion each time)
But, if you eat 100g of the onion in each 3 ways of cooking, you'd get varying amounts of carbs due to the differing water content. Carbs don't get added or disappear.