{"id":1415,"date":"2025-10-31T10:30:38","date_gmt":"2025-10-31T10:30:38","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=1415"},"modified":"2025-10-31T10:35:48","modified_gmt":"2025-10-31T10:35:48","slug":"passing-a-method-to-be-called-to-a-class","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/delegate\/passing-a-method-to-be-called-to-a-class","title":{"rendered":"Passing a method to be called to a class"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">In the class you want to call your method<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\tpublic delegate void Delegate_MyMethod(string Name);\n\n\tprivate readonly DelegateMyMethod Delegate_MyMethod1 = null;\n\n\t\tpublic MyClassName(Delegate_MyMethod MyMethod)\n\t\t{\n\t\t\tDelegate_MyMethod1 = MyMethod;\n\n\t\t}\n\n\/\/Calling it:\n\tif (Delegate_MyMethod1 != null)\n\t\tDelegate_MyMethod1(\"Something\");<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">In your class that has the method your want the other class to be able to call<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/The method to be called:\n\tpublic void MyMethod(string Name)\n\t{\n\n\t}\n\n\/\/Passing it to the other class\n\tMyOtherClass1 = new MyOtherClass(MyMethod);\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the class you want to call your method In your class that has the method your want the other class to be able to call<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[160],"tags":[],"class_list":["post-1415","post","type-post","status-publish","format-standard","hentry","category-delegate"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/1415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=1415"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/1415\/revisions"}],"predecessor-version":[{"id":1419,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/1415\/revisions\/1419"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=1415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=1415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=1415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}