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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:58:53+00:00 2026-05-15T19:58:53+00:00

Given: protected class Marker { public string Name { get; set; } public string

  • 0

Given:

    protected class Marker { 
        public string Name { get; set; }
        public string Lat { get; set; }
        public string Long { get; set; } 
    };

List<Marker> allMarkers = new List<Marker>();
allMarkers.Add(new Marker{Name="Bondi Beach", Lat = "-33.890542", Long = "151.274856"});
allMarkers.Add(new Marker{Name="Coogee Beach", Lat = "-33.923036", Long = "151.259052"});
allMarkers.Add(new Marker{Name="Cronulla Beach", Lat = "-34.028249", Long = "151.157507"});
allMarkers.Add(new Marker{Name="Manly Beach", Lat = "-33.800101", Long = "151.287478"});
allMarkers.Add(new Marker{Name="Maroubra Beach", Lat = "-33.950198", Long = "151.259302"});

I’d like to convert to a string in this format:

['Bondi Beach', -33.890542, 151.274856],
['Coogee Beach', -33.923036, 151.259052],
['Cronulla Beach', -34.028249, 151.157507],
['Manly Beach', -33.800101, 151.287478],
['Maroubra Beach', -33.950198, 151.259302]

Is there a one liner way to do this, something similar to string.Join(), or do I have to do it manually via a foreach on the List and use stringbuilder.appendformat()?

  • 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-15T19:58:54+00:00Added an answer on May 15, 2026 at 7:58 pm

    If Marker is your own class, consider overriding the ToString() method to display each line the way you do. Then, you can use a simple String.Join() to combine it all together.

    protected class Marker
    {
        public string Name { get; set; }
        public string Lat { get; set; }
        public string Long { get; set; }
        public override string ToString()
        {
            return String.Format("['{0}', {1}, {2}]", Name, Lat, Long);
        }
    };
    

    Then, to use:

    List<Marker> allMarkers = new List<Marker>();
    allMarkers.Add(new Marker { Name = "Bondi Beach", Lat = "-33.890542", Long = "151.274856" });
    allMarkers.Add(new Marker { Name = "Coogee Beach", Lat = "-33.923036", Long = "151.259052" });
    allMarkers.Add(new Marker { Name = "Cronulla Beach", Lat = "-34.028249", Long = "151.157507" });
    allMarkers.Add(new Marker { Name = "Manly Beach", Lat = "-33.800101", Long = "151.287478" });
    allMarkers.Add(new Marker { Name = "Maroubra Beach", Lat = "-33.950198", Long = "151.259302" });
    Console.Write(String.Join(",\n", allMarkers));
    

    Note: If you are dealing with a lot of markers and notice bad performance, consider rewriting that String.Format() line as:

    return "['" + Name + "', " + Lat.ToString() + ", " + Long.ToString() + "]";
    

    You may notice this is better (or worse), depending on your use case.

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

Sidebar

Related Questions

Given this code: public class Car { public virtual int CarId { get; set;
Given the sample code: class Base { public: bool pub; protected: bool prot; };
Given the following classes: public class Class1<TObject> { protected void MethodA<TType>(Expression<Func<TObject, TType>> property, ref
Given this code: class Base{ public: Base(); virtual ~Base(); }; class Derived: protected Base{
Given you have the following class (bad C#, but you get the drift): public
How can i use these methods protected Class recompile(URL source, String className, Class oldClass)
Given a random class: public class A<T> { public T t; public A ()
The title describes my problem. E.g. public class EntryDAOModule extends AbstractModule { @Override protected
Given the code: class Foo { public: Foo() {} int foo() const { return
I have a code like this: protected <T> T doSomething(String someParam, Class<T> clazz) {

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.