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. Passing an array to a method?

Passing an array to a method?

Scheduled Pinned Locked Moved C#
questioncsharpc++data-structures
3 Posts 3 Posters 0 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.
  • K Offline
    K Offline
    Kuang Cao
    wrote on last edited by
    #1

    Hi, I have a question related to passing an array to a method. In C++, if I have an array Arr[] with 20 elements, and I want to pass the array to a method, but starts from the 10th element, then I would do the following: AMethod(Arr + 10); If I want to do the same thing in C#, what would be the proper way? Thanks a lot.

    E J 2 Replies Last reply
    0
    • K Kuang Cao

      Hi, I have a question related to passing an array to a method. In C++, if I have an array Arr[] with 20 elements, and I want to pass the array to a method, but starts from the 10th element, then I would do the following: AMethod(Arr + 10); If I want to do the same thing in C#, what would be the proper way? Thanks a lot.

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      Pass the offset and length. It is always a good practice.

      A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

      1 Reply Last reply
      0
      • K Kuang Cao

        Hi, I have a question related to passing an array to a method. In C++, if I have an array Arr[] with 20 elements, and I want to pass the array to a method, but starts from the 10th element, then I would do the following: AMethod(Arr + 10); If I want to do the same thing in C#, what would be the proper way? Thanks a lot.

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

        Use the System.ArraySegment generic class.

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        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