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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:30:45+00:00 2026-06-12T15:30:45+00:00

I have this class Variables public class Variables { public enum DataType { INT,

  • 0

I have this class Variables

public class Variables
{

    public enum DataType
    {
        INT, CHAR, BOOL, FLOAT
    }

    public string Name { get; set; }
    public DataType Type { get; set; }
    public object Value { get; set; }

    public Variables(string name, DataType type, object value)
    {
        Name = name;
        Type = type;
        Value = value;
    }

}

It is also assumed that Name is unique. And inside another class I have a list of variables, List<Variables>

public void Main()
{
    List<Variables> varList = new List<Variables>();
    varList.Add(new Variables("x",DataType.BOOL, true));
    varList.Add(new Variables("y",DataType.BOOL, false));
    varList.Add(new Variables("z",DataType.BOOL, true));
    varList.Add(new Variables("a",DataType.INT, 1));
    varList.Add(new Variables("b",DataType.INT, 10));

    // I need this to convert into LiNQ.
    foreach (Variables _x in varList)
    {
        if (_x.Name == "z")
        {
            _x.Value = false;
        }
    }
}

How can I convert foreach into LiNQ? I tried .Where, .Select but they return IEnumerable. Is there a LinQ method that returns only a single value that matches to a given condition? eg,

Variables _var = varList.MethodName(LambDa Expression).....
  • 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-12T15:30:47+00:00Added an answer on June 12, 2026 at 3:30 pm

    Well you can use Single:

    varList.Single(x => x.Name == "z").Value = false;
    

    That will fail if there’s anything other than exactly one match though.

    Alternatives are SingleOrDefault, FirstOrDefault, First, LastOrDefault and Last. For example, if you expect “0 or 1” results:

    var match = varList.SingleOrDefault(x => x.Name == "z");
    if (match != null)
    {
        match.Value = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class that looks like this: class A { public: class variables_map vm
I have a class level price variable decalred inside a page, like this: public
I have a String variable say strHTML = <div class='abc'> This is a test
I have this class: Class B { private String D; private String E; }
I have this class which i would like to map: public class Contract {
I have the following code: class EmployeeFactory { public enum EmployeeType { ManagerType, ProgrammerType,
So for example I have this code: class Object{ public $tedi; public $bear; ...some
This is a simplified example. I have this enum declaration as follows: public enum
Here is what I have: public interface IEvent { int Id string Title }
This has defeated me. I want to have a static class variable which is

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.