foreach statement cannot operate on variables of type 에러 현상
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
foreach (WATATMEGA128Sim.Lines ls in this.oLines)
{
}
위 형태로 코드가 작성되었을 때 아래와 같은 에러가 발생할때가 있습니다.
오류 1 foreach statement cannot operate on variables of type 'WATATMEGA128Sim.Lines' because 'WATATMEGA128Sim.Lines' does not contain a public definition for 'GetEnumerator' D:\data2\WAT_APP\WATATMEGA128Sim\WATATMEGA128Sim\WATATMEGA128Sim\Pin.cs 25 17 WATATMEGA128Sim
foreach 에서는 System.Collections.IEnumerable 를 사용하게 되어 있는데,
System.Collections.Generic.IEnumerable 는로 사용되어서 나타나는 현상이라고 합니다 ;
foreach statement cannot operate on variables of type 해결 방법
이럴 땐 아래처럼 IEnumerable 형태로 변환한 후 사용하면 됩니다.
System.Collections.IEnumerable scEnum = this.oLines as System.Collections.IEnumerable;
foreach (WATATMEGA128Sim.Lines ls in scEnum)
{
}
- [2018/02/26] List 에서 고유값 얻기 (4027)
- [2015/05/22] C#, 아두이노 간의 WIFI 통신으로 LCD 제어 (4566)
- [2015/03/19] ERROR: APK path is not specified for module (7988)
- [2015/03/19] android studio default activity not found (8861)
- [2015/03/13] 항상 마지막에 추가한 TEXT 보이게 (15782)
- [2014/01/17] ComboBox Text 편집 안되게 (14491)
- [2014/01/08] if 문에서 여러개 비교할때 (25340) *3
- [2013/12/30] C++, C# 간단한 기능 비교 (12884)
- [2013/12/18] 3자리마다 ,(콤마) 찍기 (원화, 달러 표시) (15224)
- [2013/11/26] MSVCR110.dll , MSVCR100.dll오류 (17699) *2