B
Benjamin Fallar III
hi,
i have some weird result using for loop...
here it is in vb.net.........
Module Module1
Sub Main()
For i As Integer = 1 To 3
Dim total As Integer
total += i
Console.WriteLine(total)
Next
End Sub
End Module
here it is in c#
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 3; i++)
{
int total = 0;
total += i;
Console.WriteLine(total);
}
}
}
the results are different...
i think because in c#, we cannot use the variable total if uninitialized...
how to go about this?
i have some weird result using for loop...
here it is in vb.net.........
Module Module1
Sub Main()
For i As Integer = 1 To 3
Dim total As Integer
total += i
Console.WriteLine(total)
Next
End Sub
End Module
here it is in c#
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 3; i++)
{
int total = 0;
total += i;
Console.WriteLine(total);
}
}
}
the results are different...
i think because in c#, we cannot use the variable total if uninitialized...
how to go about this?