|
Hi guys ,
I came across a piece of code similar to the below one.
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
ad test = new ad();
Ia id5 = test.testobj();
id5.display()
}
}
public interface Ia
{
void display();
}
public class b : Ia
{
public void display()
{
MessageBox.Show("do it man");
}
}
public class ad
{
public Ia testobj()
{
b gh = new b();
return gh;
}
}
My question is why should we typecast object gh to interface Ia in testobj() function as the interface object when we can directly use the object of class b to call display function.
Thans in advance,
sishya
-- modified at 5:54 Friday 27th April, 2007
|
|
|
|
|
Because the point of an interface is that lots of objects can impliment it, and, despite their differences, they can exist as an instance of that interface via the same collection, or variable.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
In this example, it is not necessary since the example doesn't do anything much. The reason to do so would be if other classes implemented the interface and you want to call display() for a collection of different classes using a common variable of type Ia.
GregD (My Blog on software development)
|
|
|
|
|
Hello I've got a problem.
In my office, the Port 1435 and 1433 under which my MSSQL Database runs is locked. But I have to use the db for the finish work of my apprentice. Is there something Like a Web based Sql Query Analyzer, where I can run SQL Code? With it I can generate my Stored Procedures and tables?
Best regards
succo
|
|
|
|
|
How does this relate to C# ?
You want to go to a website, which creates procs and tables on your local SQL Server, or which hosts one you can play with ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I search a Web Application, which i can use on my ASP.NET web space. (Something like that: http://www.codeproject.com/aspnet/WebSqlUtility.asp) The Application doesn't have to have an intelligent. I Program my Application on my local Computer and when I'm finish i will put it online. I will create script, which creates the SPs and Tables. The tool have only to exec the SQL-Code.
|
|
|
|
|
You didn't answer me - where would the database be, local to you, or local to the tool ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
sorry. local to the tool.
|
|
|
|
|
I found the "SQL Server Web Data Administrator" (http://www.microsoft.com/downloads/details.aspx?FamilyID=c039a798-c57a-419e-acbc-2a332cb7f959&displaylang=en). This is exactly, what I've searched for.
Thank you!
|
|
|
|
|
I dont see in the control that i can do it.
I need to create one sun in each node - can i use List View control ?
Thanks for any help.
|
|
|
|
|
Yes, you can put icons in the left of the list view control.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
What ? can you explain please ?
|
|
|
|
|
If you use a list view, you can associate an image list with it, and for each item, set an index into the image list for the image to show on the left corner.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks,
But i need also that each item will be check box - can i do it also ?
|
|
|
|
|
Gosh - talk about feature creep.
Yes, it can be done, but I'm not sure if it's built in, or if you need a custom control to do it. Search the code project articles, you should find something there.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Works for me. With a TreeView anyway, which is my weapon of choice, I prefer it over ListBox and CheckedListBox.
|
|
|
|
|
I have method to which object of Type ICollection is getting passed.
I want to create an object of List<> (Generic List) , with object of ICollection. Is that possible?
kumar
|
|
|
|
|
You can use the ICollection interface to iterate over the collection, and then put the items into a List, or whatever.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
thanks, but i don't want to iterate, is that direct way, like while creating ArrayList object we can directly pass ICollection object to the constructor of ArrayList so that the contents of ICollection get copied to Arraylist object, is something like possible with generic List (List<>) object?
|
|
|
|
|
I don't think so, not if the ICollection is not templated. because, the difference is, an ArrayList and an ICollection both knew they were just holding objects.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
Hi,
let me explain what i want to do.
I'd like to store properties into a LinkedList (or something similar (key, value pairs)) and then
change the control property via changing the value in this list:
something like this:
Form myForm = new Form();
LinkedList<somekeyvalueclass> list = new LinkedList<somekeyvalueclass>();
list.AddLast("width", myForm.Width);
and then by changing this property i change myForm.Width:
findPropertyByName("width").value = 500;
Maybe I'm completely wrong and it cannot be done in C#
|
|
|
|
|
Is there a reason you're doing it like this? Besides, the 500 you store in the list is different from myForm.Width.
Why don't you just do myForm.Width = 500; ?
Cheers,
Vikram.
"But nowadays, it means nothing. Features are never frozen, development keeps happening, bugs never get fixed, and documentation is something you might find on wikipedia."
- Marc Clifton on betas. Join the CP group at NationStates. Password: byalmightybob
|
|
|
|
|
Yes i know it's different and that's what i'm asking, if there is a way howto store some kind of reference to that object...
(it's kind of setup, i'd like to register properties which should be changed in certain circumstances and change them on one place)
|
|
|
|
|
Well, you could store the settings in a settings file and change the value there. That's how lots of programs do it.
Deja View - the feeling that you've seen this post before.
|
|
|
|