Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Created March 6, 2017 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmurphyscode/4be8235aa3e39a9bb02dd6cec3f13668 to your computer and use it in GitHub Desktop.
Save willmurphyscode/4be8235aa3e39a9bb02dd6cec3f13668 to your computer and use it in GitHub Desktop.
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