-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterfaceExtansionMethod.cs
50 lines (44 loc) · 1.04 KB
/
InterfaceExtansionMethod.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
/// <summary>
/// Using the extansion method implement interface.......
/// </summary>
namespace ConsoleApp43
{
public interface ITestUser
{
int id { get; set; }
string firstName { get; set; }
string lastName { get; set; }
string FormattedName();
}
static class ITestUserHelpers
{
public static string FormattedNameDefault(this ITestUser user)
{
return "LastName - " + user.lastName + " FirstName - " + user.firstName + " ID - " + user.id;
}
}
public class TestUser : ITestUser
{
public int id { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string FormattedName()
{
return this.FormattedNameDefault();
}
}
class Program
{
public static void Main()
{
var TestUser = new TestUser();
TestUser.firstName = "Harshal";
TestUser.lastName = "Raverkar";
TestUser.id = 111;
var p = TestUser.FormattedName();
Console.WriteLine(p);
Console.ReadKey();
}
}
}