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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:50:36+00:00 2026-06-11T23:50:36+00:00

In C#, I have some decimal variables with values > 0 and some equal

  • 0

In C#, I have some decimal variables with values > 0 and some equal to 0. I get these decimals from number of different text boxes on a C# winform.

What is best practice for counting how many of them have values > 0?

If the count is > 12, The variables that have the lowest values, (only the values that are non-zero) should be changed to 0

  • 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-11T23:50:37+00:00Added an answer on June 11, 2026 at 11:50 pm

    It isn’t an award-winning piece of object-oriented software engineering, but it should do the job:

    static void Main(string[] args)
    {
        var seq = Enumerable.Range(0, 12).Select(i => (decimal)i);
        Console.WriteLine(GetGreaterThanZero(seq));
    
        var arr = seq.ToArray();
        SetMinNull(arr);
        foreach(var n in arr)
            Console.WriteLine(n);
    }
    
    static int GetGreaterThanZero(IEnumerable<decimal> numbers)
    {
        return numbers.Count(n => n > 0);
    }
    
    static void SetMinNull(decimal[] numbers)
    {
        decimal min = numbers.Min();
    
        // edit: credits to daniel for this loop
        for(int i = 0; i < numbers.Length; i++)
        {
            if(numbers[i] == min) numbers[i] = 0;
        }
    }
    

    It uses collections. I’d recommend you to use them too, however. Using a lot of numbered different values is a code smell, and barely too handy I guess.

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

Sidebar

Related Questions

I've got some entities which have decimal properties on them. These entities' properties are
I have some decimal numbers in a text file represented in exponential form Eg:
I have some Decimal instances in Python. I wish to format them such that
I have written some general functions to convert between decimal and any other base-n
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some code where I am trying to use variables in a tabpage.
I am developing a windows app in c#. I have used three decimal variables:
I've got some sql returning a decimal(20,0) data type. In SSIS I have a
I have some large HEX values that I want to display as regular numbers,
I have some float values I want to convert to a string, I want

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.