Results 1 to 9 of 9

Thread: [RESOLVED] reflection issue

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Resolved [RESOLVED] reflection issue

    can someone tell me ?why the following code is not working let me know some hints.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace Reflection_sample2
              {
        public class sample2
              {
            private int i;
            public void multiply(int n,int j)
                     {
                  i=n*j;
                     }
              public string s;
                  {
                 get
                   {
                  return s;
                   }
    
    
                 set
               
                    {
                    s = value;
                    }
    
                 
                    }
                  
    
             public static int Main()
                          {
                      Type t1=typeof(sample2);
                      Memberinfo[] mem_info=t1.GetMembers();
                      Foreach (Memberinfo m_info in mem_info)
                           {
                         console.Writeline(m_info);
                             }
                            return 0;
                             }
                            }
                            }

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: reflection issue

    Perhaps you could explain to us what it is supposed to do in the first place. You said yourself that it doesn't work and yet you expect us to be able to tell what it is supposed to do simply by reading it?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: reflection issue

    Perhaps you could explain to us what it is supposed to do in the first place. You said yourself that it doesn't work and yet you expect us to be able to tell what it is supposed to do simply by reading it?
    so many error i am getting.identifier exepected,Expected class,delegate,enum,interface or struct.Kindly let me know the idea.
    Code:
    using System;
    using System.Reflection ;
    
    namespace Reflection_sample2
              {
        public class sample2
              {
            private int i;
            public void multiply(int n,int j)
                     {
                  i=n*j;
                     }
              public string s;
                  {
                 get
                   {
                  return s;
                   }
    
    
                 set
               
                    {
                    s = value;
                    }
    
                 
                    }
                  
    
             public static int Main()
                          {
                      Type t1=typeof(sample2);
                      Memberinfo[] mem_info=t1.GetMembers();
                      Foreach (Memberinfo m_info in mem_info)
                           {
                         console.Writeline(m_info);
                             }
                            return 0;
                             }
                            }
                            }
    Last edited by firoz.raj; May 30th, 2011 at 02:08 PM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: reflection issue

    The first point to note is that the formatting of your code is horrible. It's no wonder you can't write code that works because it's simply too hard to read. Try formatting your code properly for a start and then you'll have a far better chance of getting your braces to match up. Your code should look like this:
    csharp Code:
    1. using System;
    2. using System.Reflection ;
    3.  
    4. namespace Reflection_sample2
    5. {
    6.     public class sample2
    7.     {
    8.         private int i;
    9.         public void multiply(int n, int j)
    10.         {
    11.             i = n * j;
    12.         }
    13.         public string s
    14.         {
    15.             get
    16.             {
    17.                 return s;
    18.             }
    19.  
    20.  
    21.             set
    22.             {
    23.                 s = value;
    24.             }
    25.  
    26.  
    27.         }
    28.  
    29.  
    30.         public static int Main()
    31.         {
    32.             Type t1 = typeof(sample2);
    33.             MemberInfo[] mem_info = t1.GetMembers();
    34.             foreach (MemberInfo m_info in mem_info)
    35.             {
    36.                 Console.WriteLine(m_info);
    37.             }
    38.             return 0;
    39.         }
    40.     }
    41. }
    That can be read. Your original code can't. There's no excuse for having badly formatted code.

    As for the issues in your original code, the first one is here:
    Code:
    public string s;
    You don't put a semicolon after anything that will be followed by an opening brace.

    Finally, there are lots of issues with casing in your Main method. I've seen people advise you that C# is case-sensitive in at least two other threads. Hopefully this third time you will take notice.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Re: reflection issue

    Still it is saying .cannot convert from member info to bool.and other error at line 34-35.kindly let me know the idea.
    Code:
    using System;
    using System.Reflection ;
    
    namespace Reflection_sample2
              {
        public class sample2
              {
            private int i;
            public void multiply(int n,int j)
                     {
                  i=n*j;
                     }
              public string s
                  {
                 get
                   {
                  return s;
                   }
    
    
                 set
               
                    {
                    s = value;
                    }
    
                 
                    }
                  
    
             public static int Main()
                          {
                      Type t1=typeof(sample2);
                      Memberinfo[] mem_info=t1.GetMembers();
                      foreach(Memberinfo m_info in mem_info)
                           {
                               Console.WriteLine(m_info);
                             }
                            return 0;
                             }
                            }
                            }

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: reflection issue

    Your code still lacks any reasonable formatting, plus I already told you what the problem is and posted the corrected code. If you can't read what's posted then you're wasting your own time and ours.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Resolved Re: reflection issue

    Resolved
    Last edited by firoz.raj; Jul 28th, 2010 at 03:14 AM.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: reflection issue

    Open your eyes and read what I've already posted properly. If I post again what I've already posted then that tells you that it's OK to be lazy and let other people do your thinking for you. It's not. The answer is right in front of you. If you're not prepared to make the effort to read it then I'm afraid I can't be of any further help to you.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: reflection issue

    The problem is, you are not using the very helpful IDE Intellisense. you have mispelt the class MemberInfo. C# is case sensitive unlike VB.NET.

    the working code is as follows:

    Code:
    public class sample2
        {
            private int i;
            public void multiply(int n, int j)
            {
                i = n * j;
            }
            public string s
            {
                get
                {
                    return s;
                }
    
    
                set
                {
                    s = value;
                }
    
    
            }
    
    
            public static int Main()
            {
                Type t1 = typeof(sample2);
                MemberInfo[] mem_info = t1.GetMembers();
                foreach (MemberInfo m_info in mem_info)
                {
                    Console.WriteLine(m_info);
                }
                return 0;
            }
        }
    remember, to read the intellisense popup dialog when you are typing code. it saves alot of time and mistakes whilst writing code.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width