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

The Archive Base Latest Questions

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

I basically want to type in a string[] and and be able to do

  • 0

I basically want to type in a string[] and and be able to do a foreach based on newline. I tried like this but I dont believe this works.

static string[] mystrings = {"here"+
"there"+
"mine"
}

and I want to foreach it and get back one at a time. Is this possible?

  • 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-29T07:16:27+00:00Added an answer on May 29, 2026 at 7:16 am

    You just have to add new[] or new string[] in front of the curly-brace list. And use commas, not plus signs. As in

    string[] mystrings = new[] { "here", "there", "mine" };
    

    FYI, the new[] shortcut is syntactic sugar provided by C#, which infers that you specifically mean new string[]. If you are creating an array of mixed types (such as an array of object), you will have to explicitly use new object[], because otherwise the C# compiler won’t know which type you are implying. That is:

    // Doesn't work, even though assigning to variable of type object[]
    object[] myArgs = new[] { '\u1234', 9, "word", new { Name = "Bob" } };
    
    // Works
    object[] myArgs = new object[] { '\u1234', 9, "word", new { Name = "Bob" } };
    
    // Or, as Jeff pointed out, this also works -- it's still commas, though!
    object[] myArgs = { '\u1234', 9, "word", new { Name = "Bob" } };
    
    // ...althouth this does not, since there is not indication of type at all
    var myArgs = { '\u1234', 9, "word", new { Name = "Bob" } };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the user to be able to type in a fraction like: 1/2
Given this structure.. I basically want to be able to take a list of
Basically what I want to do is allow a user to type in a
I'm trying to write my first iterator class / container type. Basically, I want
I basically want to do this: grep 'example.com' www_log > example.com.YYYY-MM-DD-H:i:S.log ...with of course
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I basically want to be able to deploy multiple versions of the same EAR
Basically, I want a class to be able to implement two different versions of
I want to do something like the code listed below. Basically, I want to
So I have this code. Basically it should be able to take a stock

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.