September 2010
S M T W T F S
« Jul    
 1234
567891011
12131415161718
19202122232425
2627282930  

Categories

Sunday, 18th of April 2010 at 02:51:01 PM

List Sort()、Find()、FindAll()、Exist() in c#

How to write delegate for sort, find, findall and exist.

Response.Write("找出Name='puma'的Person→ ");
Response.Write(lstPerson.Find(delegate(Person p) { return p.Name == "puma"; }).ToString() + "<p>");

//List<T>.FindAll()
//找出Age>10的數目
Response.Write("找出Age>10的數目→ ");
Response.Write(lstPerson.FindAll(delegate(Person p) { return p.Age > 10; }).Count.ToString() + "<p>");

//List<T>.Exists()
//檢查Name='F6'是否存在
Response.Write("檢查Name='F6'是否存在→ ");
Response.Write(lstPerson.Exists(delegate(Person p) { return p.Name == "F6"; }).ToString() + "<p>");

//List<T>.Sort()
//依Name升冪排序
Response.Write("<p>依Name升冪排序↑<br/>");
lstPerson.Sort(delegate(Person p1, Person p2) { return Comparer<string>.Default.Compare(p1.Name, p2.Name); });
foreach (Person p in lstPerson)
{
Response.Write(p.ToString() + "<br/>");
}

//List<T>.Sort()
//依Name降冪排序
Response.Write("<p>依Name降冪排序↓<br/>");
lstPerson.Sort(delegate(Person p1, Person [...]

Thursday, 28th of January 2010 at 11:59:51 PM

C# deep Object clone

I made a mistake, I used shallow clone instead of deep clone. That’s second time I made this mistake.

Here is the deep clone. Remember to add [Serializable] for class.

Ref

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

public Class Test : IClonable
{
public Test()
{
}
// deep copy in separeate memory space
public object Clone()
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, this);
ms.Position = 0;
object obj [...]

Tuesday, 26th of January 2010 at 11:01:55 AM

Integrate C# code with R

For ASMS abstract Anoop and I want to incorporate our I690 class project(A Multi-PCA Approach to Glycan Biomarker Discovery using Mass Spectromtery Profile Data)  into my MultiNGlycan.

He wrote a R code which can deal with post-processing.

Remember to install rscproxy package. The error message will say you need to install rproxy.dll but it have been replace after [R] 2.8.

User can use [...]

Wednesday, 9th of December 2009 at 03:58:18 PM

How to invoke an executable program inside C#

System.Diagnostics.Process p = System.Diagnostics.Process.Start("calc.exe");
p.WaitForExit(); // Wait until the [...]

Friday, 20th of November 2009 at 04:28:20 PM

Visual studio setup project upgrade

Set an option which allow program automatic uninstall when you click  msi package.

Visual Studio – deploy RemovePreviousVersions  propertied

Continue reading Visual studio setup project upgrade

Friday, 20th of November 2009 at 01:15:01 PM

Linear least squares approximation

C# Library

ALGLIB

Matlab

a[] [...]