We help IT Professionals succeed at work.

Generic Methods in Non generic classes c#

jsbsudha asked
Last Modified: 2008-02-01
public Class state
double costs;

/// many varaiables declared
public Class state1: state

int iterators;

public void Initialize()
 // do something else
//Many variables declared


Public Class common
            Public bool  func1(state [ ] cur)//// state is used

                          { ///do something&.
Public double func2( state [ ] obj1, state obj2)///// very important (state class used)
//// Do something

Pubic Class child1 : common

Public bool  func1(state1 [ ] cur)///// state1 is used

                          { ///do something&.

Public double func2( state1 [ ] obj1, state1 obj2)////state1 class used
//// Do something


I want to override the base class  common  functions  with  child1 functions&. So if I add keywords virtual in base class  functions and override in child1 functions I am getting error that  No suitable method found to override&&.. bcos the arguments of the function differ as  state class and state1 class&.

If I change the arguments as state in  base class function and child class function&&&.It shows error bcos state1 class has additional data which state class don have.

I think the only way is to apply  generic methods in non generic classes how  can I do it here&&.I dont want to make the class generic due to some reasons&..
Watch Question

In your class child1, change the signature of your two methods func1 and func2 to take state[] parameters rather than state1[] parameters. Inside the methods, you can cast them to state1 type.


thank you very much
But when I changed the arument in the child function to state.......It shows error bcos it uses som varaibles inside the function which state class do not have.........

could u tell me how can I convert efficiently
This one is on us!
(Get your first solution completely free - no credit card required)


Thankyou very much for your reply..... I have done this yesterdaay  after seeing your comment........
thank you very much..................
Glad to have helped

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.