I have a function in file Code.xaml.cs.
public string send (string url) { //some code... } I want to call this function from another .cs file.
send("google.com"); But the debugger gives an error! How can I do this?
Answer: 1
Whenever calling a dynamic method from a class, you will have to create an instance of that class.
class Test { public string send(string url) {} } class AnotherClass { public AnotherClass() { Test t = new Test(); t.send("google.com"); } } Otherwise you can simply use the static keyword.
public static string send(..); by : Forlan07http://stackoverflow.com/users/392632Answer: 2
If the send method isn't acting as a member function in the class that it's in, you can create a static Helper class.
public static class Helpers { public static string send(string url) { ... } } Then in any other .cs file you can call:
Helpers.send("www.google.com") by : dannyp32http://stackoverflow.com/users/1592858
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog