HI..question of c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abhii
    New Member
    • Feb 2008
    • 30

    HI..question of c#

    hi everyone,,,
    can anyone please tell mi how i wil be able to know that what is the type of perticular object....for ex...this is my function declaration and i wanted to know the type of oValue....it means weather it is numeric or string etc...thanx

    public void CreateVariable( object oValue, long lCurrentCol,lon g lCurrentRow)
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by abhii
    hi everyone,,,
    can anyone please tell mi how i wil be able to know that what is the type of perticular object....for ex...this is my function declaration and i wanted to know the type of oValue....it means weather it is numeric or string etc...thanx

    public void CreateVariable( object oValue, long lCurrentCol,lon g lCurrentRow)
    There is a GetType method in the Object class ...

    Comment

    • abhii
      New Member
      • Feb 2008
      • 30

      #3
      Originally posted by r035198x
      There is a GetType method in the Object class ...
      OH thank you so much for your reply...but my intension is to have the switch on the output which i will get from that type....n gettype() returns the string...so i think so we cant have switch on the string...see my code u wil come to know that what i mean to say....but its not working.....

      public void CreateVariable( object oValue, long lCurrentCol,lon g lCurrentRow)
      {
      if (lCurrentCol > m_lNoofVariable s)
      {

      for (int i = m_lNoofVariable s + 1; i <= lCurrentCol; i++)
      {
      objCaseVariable = new CaseVariable();
      objCaseVariable .VariableType = oValue.GetType( );
      type=objCaseVar iable.VariableT ype;
      switch(type)
      {
      case "String":
      break;
      case "Int" :
      break;
      case "DateTime":
      break;

      default:
      //goto case "Int";
      break;
      }

      }
      }
      }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Use if-else instead if switch then.

        Comment

        • abhii
          New Member
          • Feb 2008
          • 30

          #5
          Originally posted by r035198x
          Use if-else instead if switch then.
          have tried kind of example but ot working........


          object s = new object();
          s = 10;
          MessageBox.Show ("" + s.GetType());
          if (s.GetType() == System.Int32)
          MessageBox.Show ("ok");



          can u please tell me how i can?

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by abhii
            have tried kind of example but ot working........


            object s = new object();
            s = 10;
            MessageBox.Show ("" + s.GetType());
            if (s.GetType() == System.Int32)
            MessageBox.Show ("ok");



            can u please tell me how i can?
            [CODE=cpp]if(s.GetType(). toString() == "System.Int 32") {
            Console.WriteLi ne("Works");
            }[/CODE]

            Comment

            • abhii
              New Member
              • Feb 2008
              • 30

              #7
              Originally posted by r035198x
              [CODE=cpp]if(s.GetType(). toString() == "System.Int 32") {
              Console.WriteLi ne("Works");
              }[/CODE]
              Thank you so much sir....Now its working....U r Great....

              Comment

              Working...