Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. type converting

type converting

Scheduled Pinned Locked Moved C#
question
12 Posts 9 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M V
    wrote on last edited by
    #1

    how can I convert a char arrayto a string? i used method ToString() but it dosn'twork .

    P I E L T 5 Replies Last reply
    0
    • M M V

      how can I convert a char arrayto a string? i used method ToString() but it dosn'twork .

      P Offline
      P Offline
      PhilDanger
      wrote on last edited by
      #2

      One of the constructors for a string takes a char[].

      1 Reply Last reply
      0
      • M M V

        how can I convert a char arrayto a string? i used method ToString() but it dosn'twork .

        E Offline
        E Offline
        ednrgc
        wrote on last edited by
        #3

        you can try: string s = new string(mycharArray);

        1 Reply Last reply
        0
        • M M V

          how can I convert a char arrayto a string? i used method ToString() but it dosn'twork .

          I Offline
          I Offline
          il_masacratore
          wrote on last edited by
          #4

          For generic purpose type converting there's a static class "Convert". There you have a "ToString([param])" method

          Visit my blog at http://dotnetforeveryone.blogspot.com/

          1 Reply Last reply
          0
          • M M V

            how can I convert a char arrayto a string? i used method ToString() but it dosn'twork .

            L Offline
            L Offline
            lsconyer
            wrote on last edited by
            #5

            I think the best way to do that is to use a generic list List chars = new List(); chars.Add('t'); Console.WriteLine(chars[0].ToString()); Lester http://www.lestersconyers.com

            L J L 3 Replies Last reply
            0
            • L lsconyer

              I think the best way to do that is to use a generic list List chars = new List(); chars.Add('t'); Console.WriteLine(chars[0].ToString()); Lester http://www.lestersconyers.com

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              lsconyer wrote:

              the best way

              The best way to fail a code review maybe!

              **

              xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
              New xacc.ide release RSS feed^

              **

              1 Reply Last reply
              0
              • L lsconyer

                I think the best way to do that is to use a generic list List chars = new List(); chars.Add('t'); Console.WriteLine(chars[0].ToString()); Lester http://www.lestersconyers.com

                J Offline
                J Offline
                Judah Gabriel Himango
                wrote on last edited by
                #7

                That's a bad idea, lester. First of all, it only returns the first character as a string, not the whole character array. Secondly, adding the chars to a list does nothing to help converting the whole thing to a string.

                Tech, life, family, faith: Give me a visit. I'm currently blogging about: Minnesota Bridge Collapses The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                1 Reply Last reply
                0
                • L lsconyer

                  I think the best way to do that is to use a generic list List chars = new List(); chars.Add('t'); Console.WriteLine(chars[0].ToString()); Lester http://www.lestersconyers.com

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  Did you look at the earlier replies at all ? your "best way" is plain wrong, it does not address the problem, it needs at least .NET 2.0, it creates more than one object, and it is in no way better than a simple string constructor. Life is study.

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                  L 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Did you look at the earlier replies at all ? your "best way" is plain wrong, it does not address the problem, it needs at least .NET 2.0, it creates more than one object, and it is in no way better than a simple string constructor. Life is study.

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                    L Offline
                    L Offline
                    lsconyer
                    wrote on last edited by
                    #9

                    My, my, my. I didn't know programmers could be so sassy. Excuse me experts. I guess I didn't understand the problem. Please forgive me.

                    Lester http://www.lestersconyers.com

                    L J 2 Replies Last reply
                    0
                    • L lsconyer

                      My, my, my. I didn't know programmers could be so sassy. Excuse me experts. I guess I didn't understand the problem. Please forgive me.

                      Lester http://www.lestersconyers.com

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      lsconyer wrote:

                      Please forgive me

                      No problem.

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                      1 Reply Last reply
                      0
                      • L lsconyer

                        My, my, my. I didn't know programmers could be so sassy. Excuse me experts. I guess I didn't understand the problem. Please forgive me.

                        Lester http://www.lestersconyers.com

                        J Offline
                        J Offline
                        Judah Gabriel Himango
                        wrote on last edited by
                        #11

                        We don't mean to be sassy, just wanted to correct a wrong answer. No harm meant.

                        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Minnesota Bridge Collapses The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                        1 Reply Last reply
                        0
                        • M M V

                          how can I convert a char arrayto a string? i used method ToString() but it dosn'twork .

                          T Offline
                          T Offline
                          tker
                          wrote on last edited by
                          #12

                          string str = new string(char[] value); Toby Russell

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups