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. cast object[] as Type[] ?

cast object[] as Type[] ?

Scheduled Pinned Locked Moved C#
visual-studiodata-structuresquestion
8 Posts 4 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.
  • F Offline
    F Offline
    FocusedWolf
    wrote on last edited by
    #1

    Hi, i'm trying to write a function where i can do this:

    private bool ParameterCheck(Type[] expected, object[] actual)
    {
    if (actual.Length != expected.Length)
    return false;

            for (int i = 0; i < actual.Length; i++)
            {  
                if(actual\[i\] as expected\[i\] == null) //vs won't let me do this
                    return false;
            }
    
            return true;
        }
    

    The goal is to check if a object array is the same length and same type as some expected parameters.

    J L U 3 Replies Last reply
    0
    • F FocusedWolf

      Hi, i'm trying to write a function where i can do this:

      private bool ParameterCheck(Type[] expected, object[] actual)
      {
      if (actual.Length != expected.Length)
      return false;

              for (int i = 0; i < actual.Length; i++)
              {  
                  if(actual\[i\] as expected\[i\] == null) //vs won't let me do this
                      return false;
              }
      
              return true;
          }
      

      The goal is to check if a object array is the same length and same type as some expected parameters.

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

      FocusedWolf wrote:

      if(actual[i] as expected[i] == null)

      if (actual[i].GetType() != expected[i])

      Life, family, faith: Give me a visit. From my latest post: "How differently the psalmist saw it! How blessed -- how truly happy with real joy! -- is the man who delights in the Law of the Lord." Judah Himango

      L 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        FocusedWolf wrote:

        if(actual[i] as expected[i] == null)

        if (actual[i].GetType() != expected[i])

        Life, family, faith: Give me a visit. From my latest post: "How differently the psalmist saw it! How blessed -- how truly happy with real joy! -- is the man who delights in the Law of the Lord." Judah Himango

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

        Oops, wrong answer, see mine :)

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4a out now (29 May 2008)

        U J 2 Replies Last reply
        0
        • F FocusedWolf

          Hi, i'm trying to write a function where i can do this:

          private bool ParameterCheck(Type[] expected, object[] actual)
          {
          if (actual.Length != expected.Length)
          return false;

                  for (int i = 0; i < actual.Length; i++)
                  {  
                      if(actual\[i\] as expected\[i\] == null) //vs won't let me do this
                          return false;
                  }
          
                  return true;
              }
          

          The goal is to check if a object array is the same length and same type as some expected parameters.

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

          Look at Type.IsInstanceOfType()

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          1 Reply Last reply
          0
          • F FocusedWolf

            Hi, i'm trying to write a function where i can do this:

            private bool ParameterCheck(Type[] expected, object[] actual)
            {
            if (actual.Length != expected.Length)
            return false;

                    for (int i = 0; i < actual.Length; i++)
                    {  
                        if(actual\[i\] as expected\[i\] == null) //vs won't let me do this
                            return false;
                    }
            
                    return true;
                }
            

            The goal is to check if a object array is the same length and same type as some expected parameters.

            U Offline
            U Offline
            User of Users Group
            wrote on last edited by
            #5

            Brilliance. You would have thought that runtime would let you call the method and catch the exception :) (no language in the world should allow for that scenario)

            1 Reply Last reply
            0
            • L leppie

              Oops, wrong answer, see mine :)

              xacc.ide - now with TabsToSpaces support
              IronScheme - 1.0 alpha 4a out now (29 May 2008)

              U Offline
              U Offline
              User of Users Group
              wrote on last edited by
              #6

              I see them both wrong, see another one :)

              L 1 Reply Last reply
              0
              • U User of Users Group

                I see them both wrong, see another one :)

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

                You could, but them the method would not be called paramatercheck.

                xacc.ide - now with TabsToSpaces support
                IronScheme - 1.0 alpha 4a out now (29 May 2008)

                1 Reply Last reply
                0
                • L leppie

                  Oops, wrong answer, see mine :)

                  xacc.ide - now with TabsToSpaces support
                  IronScheme - 1.0 alpha 4a out now (29 May 2008)

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

                  Bah, well, I made his code compile, didn't fix his problems. Call me an ugly patcher. ;)

                  Life, family, faith: Give me a visit. From my latest post: "How differently the psalmist saw it! How blessed -- how truly happy with real joy! -- is the man who delights in the Law of the Lord." 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