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

  • Home
  • SEARCH
  • 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 7771851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:45:00+00:00 2026-06-01T16:45:00+00:00

I am looking for a better way to update values in my List/Array: My

  • 0

I am looking for a better way to update values in my List/Array:

My code is like –

String[] values = baseValue.Split(new []{'+'}); 

Because the ‘values’ can have decimal/string values – I want to update items in this list to remove any value after decimal –

for (int i = 0; i < values.Count(); i++)
{
    decimal newvalue;
    if (Decimal.TryParse(values[i], out newvalue))
    {
        values[i] = Decimal.ToInt32(newvalue).ToString();
    }
}

Is there a better way to achieve above using Linq/without Linq ?

  • 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-01T16:45:01+00:00Added an answer on June 1, 2026 at 4:45 pm

    You could use string operations, instead of converting to decimal then to int and finally back to string.

    string[] values = baseValue.Split('+');
    for (int i = 0; i < values.Length; i++)
    {
        int pos = values[i].IndexOf('.');
        if (pos >= 0) {
            values[i] = values[i].Substring(0, pos);
        }
    }
    

    Of cause no rounding occurs here.


    String.Split has an overload with one argument params char[] separator. Because of the params keyword, you can specify as many characters as you want, without having to create an array explicitly.

    string[] result = s.Split('x', 'y', 'z');
    

    Use values.Length which is a property built into array types. values.Count() is a LINQ extension method, which enumerates all the array items and is therefore not efficient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a better way to do the following query. I have a
I am looking to provide a better way of managing the distribution and storage
Is there any better way to make this query work? I'm looking for a
I'm looking for a better solution for two things: How can I understand if
Im new to wpf, and looking for good tutorials to help understand triggers better
This problem is old and basic but I can't figure out a better way
I'm looking for a way to invert arbitrary NSColor values at runtime, and there
I'm looking for a way to do a Update Panel in ASP.NET MVC 3.
Looking for a better Windows XP command-line interface. The Visual Studio Command Prompt isn't
I am looking for a better solution than what we currently have to deal

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.