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. Send a double to array

Send a double to array

Scheduled Pinned Locked Moved C#
data-structures
5 Posts 4 Posters 2 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.
  • S Offline
    S Offline
    sina rahimzadeh
    wrote on last edited by
    #1

    Hi I have an array and i want to put the ّFloat Variable into the array.

    A L B 3 Replies Last reply
    0
    • S sina rahimzadeh

      Hi I have an array and i want to put the ّFloat Variable into the array.

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      What kind of array do you have? You can convert the float to another type for e.g. int by using Convert.ToInt() method[^]. If you need to convert the entire array to another type, use the ConvertAll<> method[^].

      A new Windows Phone App - Speed Dial

      S 1 Reply Last reply
      0
      • S sina rahimzadeh

        Hi I have an array and i want to put the ّFloat Variable into the array.

        L Offline
        L Offline
        Liam Cairns Kelly
        wrote on last edited by
        #3

        Are you wondering how to assign a variable to an array? If your array is a Float type then it's rather straight forward, see below.

        float[] Variable = new float[ /*Insert how many index's the variable should hold*/ ];
        Variable[0] = //insert variable here

        Basically, the Variable[0] is the new variable array with the index (place of the array that you want to write on) which always begins at 0. So, in this case the first index of the array is 0, the second index is 1 and so on and so fourth. If you need to put a variable that isn't of the float type then you can convert it into that type using the command below.

        Convert.toInt32();

        Hope this has been of some help and I didn't make it seem over complicated! :P Best of luck learning c#. :)

        1 Reply Last reply
        0
        • A Abhinav S

          What kind of array do you have? You can convert the float to another type for e.g. int by using Convert.ToInt() method[^]. If you need to convert the entire array to another type, use the ConvertAll<> method[^].

          A new Windows Phone App - Speed Dial

          S Offline
          S Offline
          sina rahimzadeh
          wrote on last edited by
          #4

          There is no problem in convert. I want to put each digit of float in each index of float array.

          1 Reply Last reply
          0
          • S sina rahimzadeh

            Hi I have an array and i want to put the ّFloat Variable into the array.

            B Offline
            B Offline
            BillWoodruff
            wrote on last edited by
            #5

            To "echo" the question raised by AbhinavS's comment: unless we know what type of array (array[float], array[int], array[double], array[?]) you have to begin with, and why you want to stick a float in it if the Array is not of Type 'float: we really can't answer this question. You might want to read about (from MSDN documentation) the 'Float type:[^]. And, may I also suggest you click on the links at the bottom of this page that lead to content on Implicit and Explicit conversion of numeric Types. In any case I suggest you think about using a Generic List, rather than an Array. Here's something else for you to think about:

            // _you must declare the following 'using directiv_e
            using System.Collections.Generic;
            //
            // this will compile, and what appear to be integers will be converted to type double
            public List doubleList = new List {1, 2.0, 3.3333, 100038};
            //
            // this will not compile, because there is no implicit conversion of a double to a float
            public List floatList = new List {1, 2.0, 3.3333};

            best, Bill

            "Everything we call real is made of things that cannot be regarded as real." Niels Bohr

            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