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 6149117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:23:52+00:00 2026-05-23T19:23:52+00:00

Scenario: i have a web form from where i m taking input for Item

  • 0

Scenario:
i have a web form from where i m taking input for Item class now i want to assign values to feature that have return type of list how can i do that.

item value = new item(),
value.feature = serialtextbox.text; //error

foreach ( var item in value) //error 
{
 item.SerialNo= serialtextbox.text; 
}

Item and Item feature classes

Class Item
{
 list<Itemfeature> features;
 }

 class ItemFeature
  {  
    public int SerialNo
    {
        get { return serialno; }
        set { serialno = value; }
    }

    public int Weight
    {
        get { return weight; }
        set { weight = value; }
    }

}

Plz help me out

  • 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-05-23T19:23:53+00:00Added an answer on May 23, 2026 at 7:23 pm

    Note: No language is specified, but it looks like C#. I’m assuming C# in this answer.

    It’s not really clear what you’re trying to do here, but I’ll give it a shot. First of all, you’re going to want to post the actual code you’re using. This code won’t even compile, it’s loaded with syntax errors.

    Let’s take a look at your objects first:

    class Item
    {
      List<ItemFeature> features;
    }
    
    class ItemFeature
    {  
      public int SerialNo
      {
        get { return serialno; }
        set { serialno = value; }
      }
    
      public int Weight
      {
        get { return weight; }
        set { weight = value; }
      }
    }
    

    You have a custom class, ItemFeature, which consists of a serial number (integer) and a weight (integer). You then have another custom class, Item, which consists of a list of ItemFeatures.

    Now it looks like you’re trying to add a new ItemFeature to the Item and then loop through all of them and set them again?. Something like this, perhaps?:

    Item value = new Item();
    value.features.Add(new ItemFeature { SerialNo = int.Parse(serialtextbox.Text) } );
    
    foreach (var item in value.features)
    {
      item.SerialNo = int.Parse(serialtextbox.Text); 
    }
    

    (Note that this code is probably as free-hand as your code, so I haven’t tested it or anything.)

    What I’ve changed here is:

    1. Setting the SerialNo property, rather than trying to set the ItemFeature directly to a value. You need to dig into the object’s property to set a value on that property, not just set it to the entire object.
    2. Converting the input (a string) into the property’s type (an int).
    3. Looping through the list, not the Item object itself. The Item object contains a list as a property, but the object itself isn’t a list. You can loop through the property, not through the parent object.

    A few things to ask/note:

    1. What exactly are you trying to do? You have a list of objects, but you’re only setting one and then looping through that one to set it again. Why?
    2. You may want to consider more apt class/property names. Things like “Item” can be a bit unclear.
    3. Your Item class has a public variable, features. This is generally frowned upon. It’s better to use a property. That way if you ever have to add logic behind it you won’t break compatibility outside of the object itself. The ItemFeature class has properties like this, which is good. They can be additionally shortened by using automatic properties if you’d like, just to keep things clean and simple.
    4. Note that my code isn’t doing any input checking on the serialtextbox.Text value. It should be. I presented it in a simpler form as an introductory approach to something that will work under ideal conditions. But something like the following would be better:

    var serialValue = 0;
    
    if (!int.TryParse(serialtextbox.Text, out serialValue))
    {
      // Here you would probably present an error to the user stating that the form field failed validation.
      // Maybe even throw an exception?  Depends on how you handle errors.
      // Mainly, exit the logic flow.
      return;
    }
    
    var value = new Item();
    value.features.Add(new ItemFeature { SerialNo = serialValue } );
    

    Edit: I just noticed that my call to .Add() will actually fail. You’ll want to initialize the list before trying to use it. Consider changing the Item class to something like this:

    class Item
    {
      public List<ItemFeature> features { get; set; }
    
      public Item()
      {
        features = new List<ItemFeature>();
      }
    }
    

    Two things changed here:

    1. I converted the public member to a property, as previously mentioned.
    2. I added a constructor which initializes the list so that it can be used. Otherwise, being a reference type, it would default to null. So any call to .Add() or any other method on the list would throw a NullReferenceException because there’s no object on which to call the method(s).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a survey-type form that's being populated from a web database on the
The scenario: we have a web system that automatically generates office 2003 excel files
The Scenario I have an ASP.NET web project. I want to be able to
Pretty simple scenario. I have a web service that receives a byte array that
Let me share the following scenario: I have a ASP.NET intranet Web-based application that
I have a scenario where I need to upload a file from one web
Scenario: old legacy code in rpg have to consume data from a new web
Scenario: I have a contact form on my web app, it gets alot of
[edit] We're collecting credit application data from users on a web form. I have
I have a scenario where i want : To create a data class which

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.