|
-
Jul 25th, 2010, 07:54 AM
#1
Thread Starter
Frenzied Member
[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;
}
}
}
-
Jul 25th, 2010, 07:48 PM
#2
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?
-
Jul 25th, 2010, 11:22 PM
#3
Thread Starter
Frenzied Member
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.
-
Jul 25th, 2010, 11:36 PM
#4
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:
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; } } }
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: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.
-
Jul 26th, 2010, 12:05 AM
#5
Thread Starter
Frenzied Member
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;
}
}
}
-
Jul 26th, 2010, 12:11 AM
#6
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.
-
Jul 26th, 2010, 12:17 AM
#7
Thread Starter
Frenzied Member
Re: reflection issue
Last edited by firoz.raj; Jul 28th, 2010 at 03:14 AM.
-
Jul 26th, 2010, 12:25 AM
#8
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.
-
Jul 26th, 2010, 03:03 AM
#9
PowerPoster
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|