Link to home
Create AccountLog in
Avatar of rmmarsh
rmmarshFlag for United States of America

asked on

Struct in a method...

Why can't I have this code?  It's saying the struct is an "unexpected symbol".   I have the same exact struct in another class. (this is part of a partial class).
public void SaveLevelingData()  {
			
		List<ReductionData> sArray = new List<ReductionData>();
			
		struct ReductionData {
			string reductionID;
			string reductionFS;
			string computedReduction;
		}

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

In .NET, you can't define structs within methods. You can either define them within a class or within a namespace, just not within a method.
Avatar of rmmarsh

ASKER

Tried that, but it says "a namespace can only contain types and namespace declarations".

What now? :D
List<ReductionData> sArray = new List<ReductionData>();
			
		struct ReductionData {
			string reductionID;
			string reductionFS;
			string computedReduction;
		}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Try this:

public void SaveLevelingData()
{
	List<ReductionData> sArray = new List<ReductionData>();
}

public class ReductionData {
	string reductionID;
	string reductionFS;
	string computedReduction;
}

Open in new window


Gary Davis
Avatar of rmmarsh

ASKER

Thanks...