using System.Collections.Generic;
class Program
{
static void Main()
{
int[] xs = {1,2};
List<byte> bs = new List<byte>();
foreach (byte x in xs)
{
bs.Add(x);
}
}
}
This code is OK. Apply 'Convert foreach to for'. Result:
using System.Collections.Generic;
class Program
{
static void Main()
{
int[] xs = {1,2};
List<byte> bs = new List<byte>();
for (int i = 0; i < xs.Length; i++)
{
byte x = xs[i]; // error CS0266: Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
bs.Add(x);
}
}
}
Expected:
using System.Collections.Generic;
class Program
{
static void Main()
{
int[] xs = {1,2};
List<byte> bs = new List<byte>();
for (int i = 0; i < xs.Length; i++)
{
byte x = (byte) xs[i]; // OK
bs.Add(x);
}
}
}
Description
using System.Collections.Generic;
class Program
{
static void Main()
{
int[] xs = {1,2};
List<byte> bs = new List<byte>();
foreach (byte x in xs)
{
bs.Add(x);
}
}
}
This code is OK. Apply 'Convert foreach to for'. Result:
using System.Collections.Generic;
class Program
{
static void Main()
{
int[] xs = {1,2};
List<byte> bs = new List<byte>();
for (int i = 0; i < xs.Length; i++)
{
byte x = xs[i]; // error CS0266: Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
bs.Add(x);
}
}
}
Expected:
using System.Collections.Generic;
class Program
{
static void Main()
{
int[] xs = {1,2};
List<byte> bs = new List<byte>();
for (int i = 0; i < xs.Length; i++)
{
byte x = (byte) xs[i]; // OK
bs.Add(x);
}
}
}