Click here to Skip to main content
12,947,948 members (78,404 online)
Rate this:
Please Sign up or sign in to vote.
dear all
when i write code below i get following error
can any one help me out
thanks in advance

"Type and identifier are both required in a foreach statement"

string path = null;
string Path2 = null;
string StrBackupPath = null;
int i1 = 0;
i1 = DataGrid_DisplayView.CurrentRow.Index;
if (StrBackupPath == null) {
	//path = Application.StartupPath & "\Images\" & DataGrid_DisplayView.Item(13, i1).Value
	path = "D:\\FilmPlus_MSAccess\\bin\\Debug\\Images\\" +
DataGrid_DisplayView.Item(13, i1).Value;


DicomDataSetCollection ddirs = new DicomDataSetCollection();
DicomDataSet ddir = new DicomDataSet();

DicomDataSet Patient = new DicomDataSet();
DicomDataSet Study = new DicomDataSet();
DicomDataSet series = new DicomDataSet();
DicomDataSet instance = new DicomDataSet();
DicomDataSetCollection pixelData = new DicomDataSetCollection();
int i = 0;
DicomImage im = new DicomImage();

//if root patient or study; cant open icons study wise
foreach ( Patient in ddir.Children) {
	foreach ( Study in Patient.Children) {
		foreach ( series in Study.Children) {
			foreach ( instance in series.Children) {
				pixelData = instance.Value(0x88, 0x200);
				//Attributes(&H88, &H200).Value
Posted 19-Jul-12 21:27pm
Updated 19-Jul-12 22:51pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The syntax of foreach is pretty simple:
foreach (Type variablename in Collection)

You have forgotten to add the variable name in each of the foreach statements, so it doesn't know where to put each instance in the collection:
foreach ( Patient patient in ddir.Children) {
    foreach ( Study study in patient.Children) {
        foreach ( series ser in study.Children) {
            foreach ( instance inst in ser.Children) {
                pixelData = inst.Value(0x88, 0x200);
Member 8893861 20-Jul-12 5:25am
thanks for ur reply
but i am gettting new error
Error 1 foreach statement cannot operate on variables of type 'DicomObjects.DicomDataSets' because 'DicomObjects.DicomDataSets' does not contain a public definition for 'GetEnumerator' D:\nitin\imageaccess3\imageaccess3\Form1.cs 97 13 imageaccess3

OriginalGriff 20-Jul-12 5:40am
Then you need to look at which one of the statements it is, and identify which property is the collection...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,344
CHill60 3,275
Maciej Los 2,628
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 20 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100