How to add values to multiple variables into one single variable? | C#
<p>How to add values to multiple variables into one single variable in the C#? </p>

<p>For example, I declared three variables  </p>

<pre><code>decimal number1 = 53m;

decimal number2 = 33m;

decimal total;    
</code></pre>

<p>Now, when I do like this  </p>

<pre><code>total = number1 + number2; 
</code></pre>

<p><strong>It gives an error "use of unassigned local variable"</strong>    </p>

<p>Even this won't work   </p>

<pre><code>total = number1;  
total = number2;    
</code></pre>

<p>It also doesn't work   </p>

<pre><code>total += number1 
total += number2
</code></pre>

<p>I knew in textboxes we do like this, so, I thought it can work for variable also but it's not.    </p>

<pre><code>totaltextbox.text += textbox.text1  
totaltextbox.text += textbox.text2  
</code></pre>

<blockquote>
  <p>EDIT:</p>
</blockquote>

<p>Now it is working after I assigned every value in the declaration to each variable.  </p>

<p>Earlier I only assigned them in the if statements and that was causing problem. Have a look on my method for example,  </p>

<pre><code>private decimal OilLubeCharges()
        {
           decimal oilChange_var=0m;
           decimal lubeJob_var=0m;
           decimal oilLube_var=0m;
           decimal totalOiltLubeCharges_var=0m;


            if (oilChangeCheckBox.Checked)
            {
                oilChange_var = 26.00m;

            }

            else if (lubeJobCheckBox.Checked)
            {
                lubeJob_var = 18.00m;
            }

            else if (oilChangeCheckBox.Checked &amp;&amp; lubeJobCheckBox.Checked)
            {
                oilLube_var = 26.00m + 18.00m;
            }

            totalOiltLubeCharges_var = oilChange_var + lubeJob_var + oilLube_var;  
</code></pre>

<p>I don't understand if I have given variables a value in the if statement then also it should work. Why they need a value to be given in the start?  </p>

<p>Thanks to all who put their effort. Respect!</p>