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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:25:46+00:00 2026-05-29T08:25:46+00:00

List<string> arguments = new List<string>(Environment.GetCommandLineArgs().Skip(1).Take(4)); int variant = consoleOptions.HandleInput(arguments); public int HandleInput(List<string> input) {

  • 0
List<string> arguments = new List<string>(Environment.GetCommandLineArgs().Skip(1).Take(4));
int variant = consoleOptions.HandleInput(arguments);

public int HandleInput(List<string> input)
{
        int variant = 0;

        //for (int i = 0; i < input.Count; i++)
        //{
        //    if (input[i].Contains("-s"))
        //    {
        //         variant = 1; 
        //    }
        //}

        if (input[0].Contains("-s"))
        {
            variant = 1; 

            if (!String.IsNullOrWhiteSpace(input[1]) && !String.IsNullOrWhiteSpace(input[2]))
            {
                variant = 2;        
            }

            if (!String.IsNullOrWhiteSpace(input[3]))
            {
                variant = 3;
            }
        }
        return variant;
}

I’m starting my application from Commandline.
Then I get a List of Strings (max 4).

What I want to do now is:

if the first String in List is “-s” then variant = 1

if the second and third string isn’t Empty then variant = 2

if the fourth string isn’t Empty then variant = 3

I tried some things (Code above), but the problem is, if I only get the first String (one item),
The Compiler crashes on other place (checking Second string, cause Index not accessible)..

What would be the best method?

  • 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-29T08:25:47+00:00Added an answer on May 29, 2026 at 8:25 am

    The Take(4) doesn’t guarantee that you’ll have 4 elements, it just means you won’t have more than 4. So you have to check the list length.

    if (input.Count >= 1 && input[0].Contains("-s"))
    {
        return 1;
    }
    if (input.Count >= 3)
    { 
        return 2;
    }
    if (input.Count >= 4)
    {
        return 3;
    }
    
    return 0; //what do you return if none of the conditions are met?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

static void Main(string[] args) { List<int> listArray = new List<int>(); listArray.Add(100); foreach (int item
I'm trying to use Criteria API in my new project: public List<Employee> findEmps(String name)
I have the following code: // Form the continuities list string[] continuities = new
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
import java.util.Random class Kostka { val rand = new Random(System.currentTimeMillis()) val value: List[Int] =
I want to do the following: facebook.Schema.stream_data data = api.stream.get(null, new List<string> { page_id
List<String> nameList = new List<String>(); DropDownList ddl = new DropDownList(); List is populated here,
Here's my code: List<Player> l = new List<Player>(); String[] playerNumber = {Red, Green, Blue,
for example I have extension = new List<string>(); If I look at the source
I have the following method: public static string UlList(this HtmlHelper helper, List<IEntity> entities, string

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.