Click here to Skip to main content
11,935,031 members (51,919 online)
Rate this:
Please Sign up or sign in to vote.
See more: VS2008 C# Visual-Studio
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 22:27pm
Edited 19-Jul-12 23: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

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 20 Jul 2012
Copyright © CodeProject, 1999-2015
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