|
The Abc method of the interface and the implementing class must be of the same return type.
Your interface is object and the implementation is List<int>
|
|
|
|
|
Must be same, derived type is not ok?
regards,
George
|
|
|
|
|
Your problem is the implementation of Abc();
<br />
public List<int> Abc()<br />
{<br />
return new List<int>;<br />
}<br />
</int></int>
Change the return type from "List<int>" to "object" and that will fix it.
When implementing an interface, you must copy the interface declaration directly.
Inversly, you could change
<br />
interface IFoo<br />
{<br />
object Abc();<br />
}<br />
TO
interface IFoo
{
List<int>Abc();
}
Hogan
|
|
|
|
|
Thanks Hogan,
1.
I want to confirm with you must implement the same exact type? Derived type is not allowed as well?
2.
The same rule for parameter, must be exact the same in implementation class and interface declaration?
regards,
George
|
|
|
|
|
1. Yep, the exact same type.
2. Same again, the exact same type.
Hogan
|
|
|
|
|
Thanks Hogan,
Question answered.
regards,
George
|
|
|
|
|
You need to do what is called an explicit implementation of the interface. Here is the syntax using your example:
public interface IFoo
{
object Abc();
}
public class Foo : IFoo
{
public List<int> Abc()
{
return new List<int>();
}
object IFoo.Abc()
{
return this.Abc();
}
}
|
|
|
|
|
Thanks tgrt!
regards,
George
|
|
|
|
|
|
Let's say I have a resource broker, a 'lookup resource' event and a main program that will invoke the lookup resource event. All of these reside in decoupled modules, there may be only one resource broker and of course only one lookup event definition.
I created the following classes to implement the situation above:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Program::Main");
EventBroker.Current.FireLookupResource(null, EventArgs.Empty);
Console.ReadLine();
}
}
public class EventBroker
{
private static readonly EventBroker _current = new EventBroker();
public static EventBroker Current { get { return _current; } }
public event EventHandler LookupResource;
private EventBroker() { }
public void FireLookupResource(object sender, EventArgs args)
{
Console.WriteLine("EventBroker::FireLookupResource");
if (LookupResource != null)
LookupResource(sender, args);
}
}
public class ResourceBroker
{
private static readonly ResourceBroker _current = new ResourceBroker();
public static ResourceBroker Current { get { return _current; } }
private ResourceBroker()
{
Console.Write("ResourceBroker::ResourceBroker");
EventBroker.Current.LookupResource += EventBroker_LookupResource;
}
private static void EventBroker_LookupResource(object sender, EventArgs e)
{
Console.Write("ResourceBroker::EventBroker_LookupResource");
}
}
However the output is not what I expected: the LookupResource event never gets called. That's understandable, since the ResourceBroker never gets referred in the executing code, it will not get instantiated. But what should I do to get the 'correct' output?
Creating a NoOp method in the ResourceBroker, and calling it in the Main function, works but it seems to me like an ugly hack. Am I missing something in the language keywords/features?
Thanks in advance
Luca
The Price of Freedom is Eternal Vigilance. -- Wing Commander IV
En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur.
(But the best thing God has created, is a New Day.)
-- Sigur Ròs - Viðrar vel til loftárása
|
|
|
|
|
Hmmmm... This is a bit of a tricky situation. Usually when I find myself in this situation, it means it's time to do a redesign. As a suggestion, you may want to make a BrokerManager that does all of the initialization for you, or pick an appropriate Broker class and have it take an instance of the other as a constructor argument. You can limit the instances that way, and you may be able to do away with the singleton pattern. Hope that helps somewhat.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Hi ,
i have try to open an PDF file in windows application using C# I was getting an error that type should not be null following is the code . Please Help me Urgent.
Acrobat.CAcroApp app = (Acrobat.CAcroApp)Activator.CreateInstance(Type.GetTypeFromProgID("AcroExch.App"));
app.Show();
Acrobat.CAcroAVDoc doc = (Acrobat.CAcroAVDoc)Activator.CreateInstance(Type.GetTypeFromProgID("AcroExch.AVDoc"));
doc.Open(FileName, "Computed Mileage");
Error Message is
Value cannot be null.
Parameter name: type
Thank u ,
Maruthi.
|
|
|
|
|
My guess is that Type.GetTypeFromProgID is returning a null. Try seperating this out a bit and setting a couple of checks / breakpoints to try and find out more about what's going on:
Type acroapp = Type.GetTypeFromProgID("AcroExch.AcroExch");
Type acrodoc = Type.GetTypeFromProgID("AcroExch.AVDoc");
if ((acroapp == null) || (acrodoc == null))
throw new Exception("Acrobat not installed on this system.");
Acrobat.CAcroApp app = (Acrobat.CAcroApp)Activator.CreateInstance(acroapp);
Acrobat.CAcroAVDoc doc = (Acrobat.CAcroAVDoc)Activator.CreateInstance(acrodoc);
if ((app == null) || (doc == null))
throw new Exception("Error initialising Acrobat");
app.Show();
doc.Open(FileName, "Computing Mileage"); At least laying it out like this will tell you what's going wrong (or give you more of a hint).
If you see the first exception then check your TypeIDs for Acrobat, if you see the second then check the acrobat documentation is my only suggestion.
|
|
|
|
|
I have Adobe Reader 8.0 in my system But it was still showing null
even we want to install acrobat professional in my system
|
|
|
|
|
Where in the code I provided does it fail?
|
|
|
|
|
Now i Installed Acrobat Professional & try my code then it was showing another error at app.show();
Error is
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
& the code which u have give is still showing the same error type is null
|
|
|
|
|
maruthi wrote: showing the same error type is null
Which one? This is crucial.
|
|
|
|
|
Well I've got Acrobat Pro installed and AcroExch.AcroExch ProgID doesn't exist so you'll need to find out what that ID should be.
|
|
|
|
|
Another alternative way, much simpler would be:
System.Diagnostics.Process.Start(FileName); Which'll launch the default PDF viewer on the system with the specified file.
|
|
|
|
|
|
Hi,
I have to create exe that runs at Client side and Create VPN Connection automatically.
Plz prpvide solution quickly as soon as possible.
Thanx
Seema
|
|
|
|
|
Seema Gosain wrote: Plz prpvide solution quickly as soon as possible.
This is a tad rude. Your taking a job you can't do, is not our fault, we'll help when we're able.
I found this[^] with google, does it help ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
u can use dotras downloade its in sdk and try
|
|
|
|
|
hi frnds,
i tried the foll code 4 updatin in db its gettin updated but the current value is not gettin updated in datagrid only the old value is present in txtbox.. please help..im attachin the followin code.
private void Update_DataGrid(object source, DataGridCommandEventArgs e)
{
TextBox tb;
TextBox tb1
tb = (TextBox) e.Item.Cells[1].Controls[1]; // if i put 1 in controls only then its wrkin in .NET 03(is it bcoz of tat??)
empname = tb.Text;
tb1 = (TextBox) e.Item.Cells[2].Controls[1];
city = tb1.Text;
SqlCommand myCommand = new SqlCommand("sp_update",conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@empname",SqlDbType.VarChar,20));
command.Parameters.Add(new SqlParameter("@city",SqlDbType.VarChar,20));
command.Parameters["@empname"].Value = empname;
command.Parameters["@city"].Value = city;
connection.Open();
command.ExecuteNonQuery();
conn.Close();
Datagrid1.EditItemIndex = -1;
BindData();
}
|
|
|
|
|
This looks really messy, have you stepped through it to see what happens when it fails ? Do you need the Item.Cells.Controls code, because that really is nasty looking and seems fragile.
Is this a winforms app ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|