Defenitevariables.md - brainchildservices/curriculum GitHub Wiki
Slide1
Definite Assignment Rule
Let's take a look at the example given below in the C# Language; it has a main method having an unassigned variable named "price" but when we run this, a "compile-time error" is issued. Look at the image given below.
Slide 1 Downwards
Try to assign a value to the ariable price
and look at the output, an error is issued. Look at the image below.
Slide 2
So, finally at the end we have the following points.
- A variable must be definitely assigned at each location where it's value is obtained.
- A variable must be definitely assigned at each location where it is passed as a reference parameter.
- All output parameters of a function member must be definitely assigned at each location where the function member returns.
- The "this" variable of a "struct-type" instance constructor must be definitely assigned at each location where that instance constructor returns.