|
Let's see if I can explain my small doubt. I can go around this, but as I was coding something, I got curious if something wasn't possible to do in c#.
In C++, you could have something like this:
<br />
class A<br />
{<br />
public virtual void method()<br />
{<br />
}<br />
}<br />
<br />
class AA : public A<br />
{<br />
public void method()<br />
{<br />
}<br />
}<br />
<br />
class AB : public B<br />
{<br />
public void method()<br />
{<br />
}<br />
}<br />
<br />
A *obj;<br />
<br />
if ( something )<br />
{<br />
obj = (A)( new AA() );<br />
}<br />
else<br />
{<br />
obj = (A)( new AB() );<br />
}<br />
<br />
obj->method();<br />
<br />
What happens here is that when you invoke the method function, you'll be executing the implementation from AA or from AB and not from A. Though, in C#, if I try to do something like this, you'll be executing the implementation from A. That fact to me, is a shame... I liked this behavior. And as pointers in C# only exist for values, I suppose this is not possible with C#.
Best regards
Gonçalo A.
|
|
|
|
|
Why dont you try it and see what happens?
using System;
using System.Collections.Generic;
using System.Text;
namespace VirtualMethods
{
class Program
{
static void Main(string[] args)
{
A a = new A();
A aa = new AA();
A ab = new AB();
A ac = new AC();
Console.WriteLine(a.GetValue());
Console.WriteLine(aa.GetValue());
Console.WriteLine(ab.GetValue());
Console.WriteLine(ac.GetValue());
Console.ReadLine();
}
}
}
class A
{
public virtual string GetValue()
{
return "A";
}
}
class AA : A
{
public override string GetValue()
{
return "AA";
}
}
class AB : A
{
public override string GetValue()
{
return "AB";
}
}
class AC : A
{
public override string GetValue()
{
return base.GetValue();
}
}
|
|
|
|
|
override.... right.
I feel like a newbie, but I guess these things happen when moving on to a new language :p
Thank you for the quick reply, you helped a lot.
Gonçalo A.
|
|
|
|
|
no problem You can only override a virtual or abstract method, but you can "new" a method over any old one.
i.e.
class AA : A
{
public new string GetValue()
{
return "NEW";
}
}
But this will behave how you originally described ... if cast as 'A' it'll call the original method on the A class. It'll only call the 'new' method if cast as an AA.
|
|
|
|
|
Yes, that was how I was doing it. The original was a virtual method, but I expected him to override automatically. Though, it does make more sense this way, and offers more possibilities.
Thank you, once again, for the explanation.
Gonçalo A.
|
|
|
|
|
Hi,
you should pay attention to the messages the compiler emits. If you try and redefine a
virtual method without either "new" or "override", a warning is issued.
Don't lower the warning level (a project setting, 4 is a good value) to get rid of
(some of) the messages, study the messages and adapt your code instead.
|
|
|
|
|
Yes, I noticed that already.
Thanks.
Gonçalo A.
|
|
|
|
|
hi,
In my webapplication in some pages they following error is showing but i don't know how to solve this problem.please solve my problem.error is like this.
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not find server 'WINHOSTING02' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.
/backoffice/entrysubmit.asp, line 76
please help me .
obalesu
|
|
|
|
|
obalesu wrote: please solve my problem.
No.
And why are you using ODBC to access SQL Server in the first place?
|
|
|
|
|
hi all,
how can we show a progress bar to the user while loading data in dataset from sql server database.please help me .
Thanks For Any Body Hellp me
|
|
|
|
|
I tried to do a similar thing a long time ago, at that time I was thinking abt getting some sort of progress from SQL server but in theend I came to know that it wasnt possible. probably u can show some other graphic while the data is being loaded and hide that when ur done.
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
Rocky is probably right - unless you've got a known, fixed start and end point and status updates along the way (which you don't have with SQL loads), a progress bar is probably not the right UI choice.
Something that indicates a long-running process is probably better - a loading circle or an animated gif. There are some great loading circles here on Code Project.
It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein
|
|
|
|
|
Hi All,
I am have created some custom controls so i have a dll.
Now i want create my own toolbox and wana add these controls to this toolbox.
But i don't know yet how to create a toolbox.
if anyone knows pls tell me.
Praveen Sharma
|
|
|
|
|
right click on toolbar>Choose Items>> Select ur DLL and ok
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
Hi all,
How can we show a progress bar while loading data into datagrid from database(sql server).
please help me.
thanks in advance
|
|
|
|
|
hi all,
I Have created one Windows application with c# and sqlserver.after completion setup file.in solution explorer window the detected dependencies are:
ms.net framework,
dao360.dll,
excel.exe,
interop.access.dll,
interop.dao.dll,
interop.excel.dll,
interop.microsoft.office.core.dll,
interop.owc10.dll,
interop.vbide.dll,
msacc.olb,
mscomctl.dll,
mso.dll,
owc10.dll,
vbe6ext.olb
please help me inthis problem how can i deploy this windows application.
thanks in advance.
|
|
|
|
|
|
thank you sending reply.
how can i add these dependencies to set up project.
|
|
|
|
|
As a beginner about making WebService routines and caller applications, I prepared WebService Application that have a few functions in Visiual Studio using C#, .Net 2.0. And I have written a client application running under WindowsCe that calls those WebSevice functions located in a Server environemnt.
The system works well except for first calls. I mean: When the client calls a WebService function for the FIRST time, it takes considerable time ( at least 8-10 seconds) the functions executes and return back. Immediately after the first call, the next calls (to same function) works in good speed.
So Why first calls always takes time..?
Note: In Web service side, I did not use any attribute for functions. Should I use?
|
|
|
|
|
I've struggled with this too. i found it was because internet explorer was set to automatically detect proxy settings.
so. if it's set your program will try to find a proxy server and wait for timeout.
add a proxy object:
<br />
System.Net.WebProxy objProxy = new System.Net.WebProxy("http://1.2.3.5:8080/", true);<br />
YourService.Proxy = objProxy;<br />
or if you dont have a proxy
<br />
YourService.Proxy = null; <br />
it might work.
If it' stuck, DO NOT pull harder!
|
|
|
|
|
Hi all,
Can anybody help me here ... how to run a procedure with outparameter...
please provide the code if u can... Thanks alot
T@SU
|
|
|
|
|
using (SqlConnection sc = new SqlConnection())
{
StringBuilder sql = new StringBuilder();
sql.Append("exec sp_YourProc");
string connStr = "...";
sc.ConnectionString = connStr;
sc.Open();
using (SqlCommand sco = new SqlCommand())
{
try
{
sco.CommandType = CommandType.Text;
sco.CommandText = sql.ToString();
sco.Connection = sc;
using (SqlDataReader sr = sco.ExecuteReader())
{
}
}
catch (SqlException exc)
{
}
}
SkyWalker
|
|
|
|
|
Where's the output param the OP asked about?
|
|
|
|
|
use sco.Parameters.Add()
SkyWalker
|
|
|
|
|
Same as any normal procedure, just make sure you add the output parameter and give it a Direction of Output (or InputOutput)
SqlParameter outParam = new SqlParameter("@myOutParam",SqlDbType.Int);<br />
outParam.Direction = ParameterDirection.Output;<br />
myCmd.Parameters.Add(outParam);
|
|
|
|