Created
March 6, 2017 12:02
-
-
Save willmurphyscode/4be8235aa3e39a9bb02dd6cec3f13668 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApplication | |
{ | |
public class HasInstanceAndStaticMethods | |
{ | |
public static void StaticMethod() | |
{ | |
Console.WriteLine("Hello from static method"); | |
} | |
public void InstanceMethod() | |
{ | |
Console.WriteLine($"Type in instance method is {this.GetType().FullName} "); | |
} | |
public void CallStaticMethodFromInstanceMethod() | |
{ | |
Console.Write("Attempting to call static method from instance method..."); | |
StaticMethod(); | |
Console.WriteLine("... and it succeeded."); | |
} | |
} | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
HasInstanceAndStaticMethods.StaticMethod(); | |
var instance = new HasInstanceAndStaticMethods(); | |
instance.InstanceMethod(); | |
instance.CallStaticMethodFromInstanceMethod(); | |
} | |
} | |
} | |
// Output: | |
// Type in instance method is ConsoleApplication.HasInstanceAndStaticMethods | |
// Attempting to call static method from instance method...Hello from static method | |
// ... and it succeeded. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment