How can I get the name of a variable passed into a function?

What you want isn’t possible directly but you can use Expressions in C# 3.0: public void ExampleFunction(Expression<Func<string, string>> f) { Console.WriteLine((f.Body as MemberExpression).Member.Name); } ExampleFunction(x => WhatIsMyName); Note that this relies on unspecified behaviour and while it does work in Microsoft’s current C# and VB compilers, and in Mono’s C# compiler, there’s no guarantee that … Read more

What is the ProgId or CLSID for IE9’s Javascript engine (code-named “Chakra”)

The CLSID for the Chakra Javascript engine installed with IE9 is {16d51579-a30b-4c8b-a276-0ff4dc41e755}. The InProcServer32 is %windir%\System32\jscript9.dll . There is no ProgId that I could find. That’s a bit odd; normally paired ProgId and CLSID entries refer to each other. For a given COM object, the ProgId key in the registry has a subkey called CLSID, … Read more

Correlation of two arrays in C#

You can have the values in separate lists at the same index and use a simple Zip. var fitResult = new FitResult(); var values1 = new List<int>(); var values2 = new List<int>(); var correls = values1.Zip(values2, (v1, v2) => fitResult.CorrelationCoefficient(v1, v2)); A second way is to write your own custom implementation (mine isn’t optimized for … Read more

Log off user from Win XP programmatically in C#

You could P/Invoke ExitWindowsEx: http://www.pinvoke.net/default.aspx/user32/ExitWindowsEx.html Pulling it all together: using System.Runtime.InteropServices; class Class1 { [DllImport(“user32.dll”)] static extern bool ExitWindowsEx(uint uFlags, uint dwReason); [STAThread] static void Main(string[] args) { ExitWindowsEx(ExitWindows.LogOff, ShutdownReason.MajorOther | ShutdownReason.MinorOther); } } [Flags] public enum ExitWindows : uint { // ONE of the following five: LogOff = 0x00, ShutDown = 0x01, Reboot = … Read more

How do I get the Local Network IP address of a computer programmatically?

If you are looking for the sort of information that the command line utility, ipconfig, can provide, you should probably be using the System.Net.NetworkInformation namespace. This sample code will enumerate all of the network interfaces and dump the addresses known for each adapter. using System; using System.Net; using System.Net.NetworkInformation; class Program { static void Main(string[] … Read more

Encrypting Web.Config

Here are the commands to encrypt web.config file without any programming… For encryption aspnet_regiis -pef “Section” “Path exluding web.config” For Decryption aspnet_regiis -pdf “Section” “Path exluding web.config” From this commands you can encrypt or decrypt all the section.