Click here to Skip to main content
15,889,825 members
Home / Discussions / C#
   

C#

 
QuestionReusing a socket Pin
Chals24-Aug-07 22:30
Chals24-Aug-07 22:30 
Question)c# Pin
lankaudaranga24-Aug-07 22:20
lankaudaranga24-Aug-07 22:20 
AnswerRe: )c# Pin
Christian Graus25-Aug-07 0:50
protectorChristian Graus25-Aug-07 0:50 
GeneralRe: )c# Pin
Paul Conrad25-Aug-07 9:28
professionalPaul Conrad25-Aug-07 9:28 
Questionc# Pin
lankaudaranga24-Aug-07 22:10
lankaudaranga24-Aug-07 22:10 
AnswerRe: c# Pin
Rami Said Abd Alhalim25-Aug-07 2:57
Rami Said Abd Alhalim25-Aug-07 2:57 
AnswerRe: c# Pin
Paul Conrad25-Aug-07 9:28
professionalPaul Conrad25-Aug-07 9:28 
QuestionIs there a solution to this problem? (Permanent casting) [modified] Pin
zsavas24-Aug-07 21:14
zsavas24-Aug-07 21:14 
Hello all,
I wonder if the following problem is possible in c#:

I have two classes named class1 & class2 both having two functions named func1 & func2. Although the function names are the same, what they do are different for two classes.
I want to declare only one object to use these functions.

In order to do what the following code portion does
class1 obj1 = new class1();
class2 obj2 = new class2();
if (selection == 1) // Means call the class1's func1
   obj1.func1();
else if (selection == 2) // Means call class2's func1
   obj2.func1();

I need a shorter and smarter way i.e;
The above code is possible but it is too long. You should write if statements every time you want to call the functions. So I want to do this with a shorter code:
I have an object which is assigned to the obj1 or obj2 (which are declared as above) depending on the selection at the beginning of the program, then you can call the funcs just by obj.func1()

I dont want to write if statements each time i am calling the functions.
Declaring an object of type object is OK but this time you have to cast the obj which is of type object to class1 (or class2) each time you are calling the functions. So casting is a not a solution either. I think i am looking for something like "Permanent casting" (if exists of course)?

P.S : One of the classes may have extra funcs which the other doesnt contain so "Inheritance" is not enough Blush | :O

Regards
Zafer


-- modified at 4:36 Saturday 25th August, 2007
AnswerRe: Is there a solution to this problem? (Permanent casting) Pin
Christian Graus24-Aug-07 21:30
protectorChristian Graus24-Aug-07 21:30 
GeneralRe: Is there a solution to this problem? (Permanent casting) Pin
zsavas24-Aug-07 22:30
zsavas24-Aug-07 22:30 
GeneralRe: Is there a solution to this problem? (Permanent casting) Pin
Christian Graus25-Aug-07 0:51
protectorChristian Graus25-Aug-07 0:51 
AnswerRe: Is there a solution to this problem? (Permanent casting) Pin
Urs Enzler24-Aug-07 23:32
Urs Enzler24-Aug-07 23:32 
AnswerRe: Is there a solution to this problem? (Permanent casting) Pin
PhilipPainter27-Aug-07 11:38
PhilipPainter27-Aug-07 11:38 
Questioncopy Xml to Xml files Pin
ytubis24-Aug-07 20:44
ytubis24-Aug-07 20:44 
AnswerRe: copy Xml to Xml files Pin
Christian Graus24-Aug-07 21:10
protectorChristian Graus24-Aug-07 21:10 
AnswerRe: copy Xml to Xml files [modified] Pin
Hessam Jalali24-Aug-07 21:26
Hessam Jalali24-Aug-07 21:26 
QuestionIO problem Pin
sianatia24-Aug-07 20:16
sianatia24-Aug-07 20:16 
AnswerRe: IO problem Pin
Christian Graus24-Aug-07 21:09
protectorChristian Graus24-Aug-07 21:09 
GeneralRe: IO problem Pin
sianatia25-Aug-07 18:14
sianatia25-Aug-07 18:14 
QuestionString Manipulation Pin
Senu Gandhi24-Aug-07 19:19
Senu Gandhi24-Aug-07 19:19 
AnswerRe: String Manipulation Pin
Christian Graus24-Aug-07 19:54
protectorChristian Graus24-Aug-07 19:54 
GeneralRe: String Manipulation Pin
zhongyougang@gmail.com24-Aug-07 20:56
zhongyougang@gmail.com24-Aug-07 20:56 
GeneralRe: String Manipulation Pin
PIEBALDconsult25-Aug-07 4:44
mvePIEBALDconsult25-Aug-07 4:44 
GeneralRe: String Manipulation Pin
Paul Conrad25-Aug-07 9:30
professionalPaul Conrad25-Aug-07 9:30 
JokeRe: String Manipulation Pin
Luc Pattyn24-Aug-07 23:44
sitebuilderLuc Pattyn24-Aug-07 23:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.