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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:27:07+00:00 2026-05-18T00:27:07+00:00

Hey everyone. I have a function that works both with short input values, as

  • 0

Hey everyone. I have a function that works both with short input values, as with byte input values, here pixelData is an array filled with either bytes or shorts.

       byte oColor;
        if (pixelData[counter/3] < minValue)
            oColor = 0;
        else if (pixelData[counter/3] > maxValue)
            oColor = 255;
        else
            oColor = (byte)(((pixelData[counter/3] - (WindowLevel - (WindowWidth / 2))) * 255) / WindowWidth);

Then I have the following code:

bool isShort = ReadIsShort();
if(isShort){
 shortArray = ReadShortArray();
} else {
 byteArray = ByteArray();
}

To get either the short or the byte array. However, I cannot use them in function above. Since something like this doesn’t work.

var pixelData;
if(IsShort)
 pixelData = shortArray;
else
 pixelData = byteArray;

Anyone know how I should program this, since this clearly is a design flaw.

  • 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-18T00:27:08+00:00Added an answer on May 18, 2026 at 12:27 am

    Since C# is a strongly typed language, every variable must have a well-defined type. Therefore, pixelData can only be either a short or a byte array. So far there’s no design flaw here imo.

    I assume, that your computations are more or less performance-critical (since there are pixels involved :)), so I won’t repeat the suggestion of using boxing (cast to object[]) or creating Lists or similar things.

    Even using generics is not an option, since you cannot give arithemtic type constraints for generic functions (see this qestion) The only solution I can think of is to duplicate the code and write two explicit versions, one for each data type.

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

Sidebar

Related Questions

Hey everyone, not sure what is going on here :( Basically I have a
Hey everyone. I've written this simple function that is supposed to load a portion
Hey everyone, I have written a script that downloads a zip file from a
hey everyone, here is the site SEE BELOW I have a slight jquery problem
Hey everyone... I'm not too familiar with PHP... but I have PHP code that
Hey everyone, I'm working on a PHP application that needs to parse a .tpl
Hey everyone, I have achieved the effect described in the title using the following
Hey everyone. I have a fair amount of experience developing iOS apps, but nothing
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey everyone, I am trying to run the following program, but am getting a

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.