0

I'm new on the C# and I have one question. I have one function for this job.

The function is static:

 FilterMethods.GetEmpDiscount(item.campaigns) //item.campaings type a Class, this function return decimal value. 

How Can I Invoke this function at other function.

5
  • No, you can call everywhere. Prefixe by the class like you do in your sample. Commented Feb 13, 2020 at 13:35
  • by using FilterMethods.GetEmpDiscount(myCampaigns)? Commented Feb 13, 2020 at 13:35
  • 1
    How Can I Invoke this function at other function you don't, just call it... Also HandleException Class what does this question have to do with Exception? Commented Feb 13, 2020 at 13:35
  • Yes. FilterMethods seems to be a Helper with statics methods. You can call statics methods with class as prefix. FilterMethods is a class, isn't it ? Commented Feb 13, 2020 at 13:37
  • @KhalilLazhar: That is incorrect. Static methods can be called from anywhere (both static and class methods). I think you may be getting confused with the fact that class methods cannot be called from inside a static method (since the static scope is independent of any particular class instance). Commented Feb 13, 2020 at 15:07

1 Answer 1

1
static void DoSomething() { } static void DoSomethingElse() { DoSomething(); } 

But this only works if the calling function is static as well.

If they are in different classes you have to write 'classname.DoSomething();' while classname is the name of the class which contains the 'DoSomething()' method.

Keep in mind that the access-modifiers are valid.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.