Dependency Injection Example: Interface Injection

by aristosamar 25. April 2011 22:26

public class Log1 : ILog

{

public string Log()

{

return "Log1";

}

public class Log2 : ILog

{

public string Log()

{

return "Log2";

}

}

//-------------------------------------------------------

static void Main(string[] args)

{

string logClass = ConfigurationManager.AppSettings["LogClass"];

Type type = Type.GetType(logClass);

ILog log = (ILog)Activator.CreateInstance(type);
string result = log.Log();

}

 

//-------------------------------------------------------

<?xml version="1.0" encoding="utf-8" ?>

<configuration><

appSettings>

<add key="Param" value="Value"/><

add key="LogClass" value="ConsoleApplication5.Log2"/> </appSettings>

</configuration>

Tags:

Playing with generics using Lambdas

by aristosamar 21. April 2011 17:54

With no further introduction, here you have a few "killer" lambdas:

List<int> list1 = new List<int>() { 1, 2 };
List<int> list2 = new List<int>() { 2, 3 };
list1.RemoveAll(c => list2.Contains(c));
//remove from list1 elements that appear as well on list2
list1.RemoveAll(c => !list2.Contains(c));
//remove from list1 elements that don't appear on list2
List<int> tmp = list1.Where(c => list2.Contains(c)).ToList();
//copy into 'tmp' elements from list1 that appear as well on list2
Quite powerfull, isn't it?

Tags: ,

C# | LINQ

Powered by BlogEngine.NET 1.4.0.0
Theme by Mads Kristensen

About the author

I give up things to be able to code and create virtual worlds... because I have a passion... I don't want to let it go... and I am greateful for it...

Recent comments

Comment RSS

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's or anyone view in  anyway.

© Copyright (C) 2008 Mariusz Zaleski