Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8469591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:16:15+00:00 2026-06-10T16:16:15+00:00

I have a list Dars using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace

  • 0

I have a list Dars

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PantaRei.Components
{
    public class Dars
    {
        public float OpBal      { get; set; }
        public float PlNeOrRec  { get; set; }
        public float MiCaCol    { get; set; }
        public float MiDeCol    { get; set; }
        public float MiWrOff    { get; set; }
        public float ClBal      { get; set; }

        public float Tot
        {
            get { return OpBal+ PlNeOrRec+ MiCaCol + MiDeCol + MiWrOff; }
        }
    }
}

I create a new dars

Dars secA1 = new Dars();

And Then I use this bit of code to fill it up

public static void GetData(ref Dars secA1, Ddr ddr, Ddrs ddrs, Type pTypes)
    {
        Array typesEnum = Enum.GetValues(pTypes);

        foreach (Enum types in typesEnum)
        {
            string pType = StringEnum.GetStringValue(types);

            secA1.OpBal = ddrs.Out.Sum(o => o.Amount);

            secA1.MiDeCol += ddr.Dil.Where(dil => dil.ProductType == pType && dil.ToBeSold).Sum(dil => dil.Amount);

            secA1.PlNeOrRec += ddr.Rec.Where(rec => rec.ToBeSold).Sum(rec => rec.Amount);

            GetMiCaCol(ref secA1, ddr, pType);
            GetMiWrOff(ref secA1, ddr, pType);
        }
    }

Now I would like to do something like this

int i = 11;
            foreach (float g in secA1)
            {
                daily.Cells[i, 4] = g;
                i++;
            }

But I’m getting this error

foreach statement cannot operate on variables of type ‘PantaRei.Components.Dars’ because ‘PantaRei.Components.Dars’ does not contain a public definition for ‘GetEnumerator’

How do I solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:16:16+00:00Added an answer on June 10, 2026 at 4:16 pm

    Just because a class has a collection of properties that happen to be floats, it doesn’t make it a collection. Your code appears to be doing what would be done a lot more appropriately with some sort of data binding. What you are attempting to do can be done by marking Dars as implementing the IEnumerable interface, and adding an implementation of the GetEnumerator method that returns the values for the float properties in your class, but I would never condone this approach in a code review. That being said, try this (if you must):

    public class Dars : IEnumerable
    {
        public float OpBal { get; set; }
        public float PlNeOrRec { get; set; }
        public float MiCaCol { get; set; }
        public float MiDeCol { get; set; }
        public float MiWrOff { get; set; }
        public float ClBal { get; set; }
    
        public float Tot
        {
            get { return OpBal + PlNeOrRec + MiCaCol + MiDeCol + MiWrOff; }
        }
    
        public IEnumerator GetEnumerator()
        {
            yield return this.OpBal;
            yield return this.PlNeOrRec;
            yield return this.MiCaCol;
            yield return this.MiDeCol;
            yield return this.MiWrOff;
            yield return this.ClBal;
            yield return this.Tot;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have List<Custom> where Custom is class Custom { public int id; public String
I have list of MyObject that looks like this: public class MyObject{ public int
Have/Want List Matching Algorithm I am implementing an item trading system on a high-traffic
I have list of the text filed in vertically. And all these are in
I have list view [text view and check box controlls] with more data. I
I have list view [text view and check box controlls] with more data. I
I have list of rows that I have fetched using mysql_fetch_array() . Now I
I have list of objects type Node ( items ). And Node class has
I have list of URL in txt file I am using it for performance
I have list of text that contain double quoate and upderscore. How can I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.