Pawel Lukasik
.net dev
the process of converting a value type to the type object or to any interface type implemented by this value type. When the CLR boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap.
https://msdn.microsoft.com/en-us/library/yz2be5wk.aspx
public void Debug(string logMessage)
{
try
{
var logger = Logger;
if (logger.IsDebugEnabled)
{
logger.DebugFormat(CultureInfo.InvariantCulture, logMessage);
}
}
catch (Exception)
{
// We don't want logger making application to crash
}
}
loggingService.Debug("StimmingService: " +
(currentStimulationControllerDecorator?.SupportedStimulationMode ?? StimulationMode.None)
+ " stopped");
void Debug<T>(string logMessage, T arg);
loggingService.Debug("StimmingService: {0} stopped",
currentStimulationControllerDecorator?.SupportedStimulationMode
?? StimulationMode.None);
public void Debug<T>(string logMessage, T arg)
{
try
{
var logger = Logger;
if (logger.IsDebugEnabled)
{
logger.DebugFormat(CultureInfo.InvariantCulture, logMessage, arg);
}
}
catch (Exception)
{
// We don't want logger making application to crash
}
}
...
loggingService.Info($"Added new patient: {newPatient.FirstName} {newPatient.LastName}");
...
do you see it?
In essence, a closure is a block of code which can be executed at a later time, but which maintains the environment in which it was first created - i.e. it can still use the local variables etc of the method which created it, even after that method has finished executing.
The general feature of closures is implemented in C# by anonymous methods and lambda expressions.
http://stackoverflow.com/questions/428617/what-are-closures-in-net#428624
int filter;
if (int.TryParse(Console.ReadLine(), out filter) == false) return;
var source = Enumerable.Range(1, 10000);
var filteredList = source.Where(i => Filter(i, filter));
int filter;
if (int.TryParse(Console.ReadLine(), out filter) == false) return;
var source = Enumerable.Range(0, 10000);
var enumerator = source.GetEnumerator();
while (enumerator.MoveNext())
{
var current = enumerator.Current;
if (current <= filter)
Console.WriteLine(current);
}
old-fashioned enumerator
ElectrodesService, FittingSessionService, DB loading client code
By Pawel Lukasik