Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Basic C# Programe

Author  Topic 

mapidea
Posting Yak Master

124 Posts

Posted - 2009-02-08 : 07:02:29
I have a code run from VS 2005 command prompt.

Why the following is giving error?

using System;

class Program
{
public static void Main(string[] args)
{
Test t = new Test();
t.set_Foo(10);
Console.WriteLine(t.Foo);
}
class Test
{
private int m_foo;
public int Foo
{
get
{
return m_foo;
}
}
public void set_Foo(int value)
{
m_foo = value;
}
}
}

Rajani6
Starting Member

2 Posts

Posted - 2009-02-10 : 07:03:59
what is the error you are getting?
Please mention the error

Cheers,
Rajani
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-02-12 : 04:25:20
If the error is compile time error then I guess the error is with the property Foo in the class.It needs to be declared as ReadOnly but cannot see anywhere the property being used.
Go to Top of Page

mapidea
Posting Yak Master

124 Posts

Posted - 2009-02-12 : 04:34:27
Yes right. The property Foo is being declared so the compiler will generate a get_Foo and set_Foo. Which will lead to error.
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-02-12 : 07:09:31
So whats the error?
Go to Top of Page

mapidea
Posting Yak Master

124 Posts

Posted - 2009-02-12 : 08:09:09
Thanks for your replies.

The error shown is

"Already defines a member called 'set_Foo' with the same parameter types"

And that is because when we define a property "Foo" the compiler creates two methods "set_Foo" and "get_Foo" automatically if not defined explicitly.

And we already have a method set_Foo and hence the error.

Thanks
Go to Top of Page
   

- Advertisement -