This blog is a knowledge base...where I clip cool tricks and urls

List and delegates

clipped from weblogs.asp.net

System.Text.StringBuilder sb = new System.Text.StringBuilder();

   31             sb.Append("<h1>List As Is</h1> using ForEach<br/> ");

   32             sb.Append("<br/><ul>");

   33             ninjas.ForEach(delegate(Ninja n)

   34             {

   35                 sb.Append(String.Format("<li>{0}, ({1})</li>", n._name, n._age));

   36             });

   37             sb.Append("</ul><br/>");

   38 

   39             ///////////////////////////////////////

   40             sb.Append("<h1>Age is greater or equal to 0</h1>using FindAll,and foreach<br/> ");

   41             sb.Append("<br/><ul>");

   42             List<Ninja> thoseAlive = ninjas.FindAll(delegate(Ninja n)

   43             {

   44                 return n._age >= 0;

   45             });

   46             thoseAlive.ForEach(delegate(Ninja n)

   47             {

   48                 sb.Append(String.Format("<li>{0}, ({1})</li>", n._name, n._age));

   49             });

   50             sb.Append("</ul><br/>");

 blog it

Async upload file

clipped from jeffzon.net

Let UpdatePanel support file uploading (1): Let's Get Started


by Jeffrey Zhao
30. March 2007 11:15

UpdatePanel cannot be used to upload files in ajax style from the very beginning. Eilon Lipton has written a blog post to explain the reason of that. As the post said, the two workarounds to resolve the problem are:


  1. Have a dedicated "Upload" button that does a regular postback instead of an async postback. You can achieve this using several techniques: Have the button be outside all UpdatePanels; have the button be the target of an UpdatePanel's PostBackTrigger; or call ScriptManager.RegisterPostBackControl() on it.

  2. Have a dedicated file upload page that doesn't have any UpdatePanels. Many web sites already do this anyway.
 blog it

C# Microsoft have added features that makes the language just a little bit dynamic

Dictionary<string, string> dic = new Dictionary<string, string>()
.Init(
new {
Key1
= "val1",
Key2
= "val3"
});

For version 3.0 of C# Microsoft have added features that makes the language just a little bit dynamic but still strongly typed. One of this feature is collection initializers for lists and dictionaries like we initialized arrays on earlier versions:

 blog it

ASP.NET MVC has arrived

clipped from blogs.msdn.com

Ok, ok, it took us a little longer than we expected, but we finally got the ASP.NET 3.5 Extension Preview posted! This is the release with all the MVC goodness you have been hearing about as well as some very cool stuff  such as Dynamic Data controls which makes building data driven web applications a breeze, AJAX history support, ADO.NET Data Services (aka Astoria), the ADO.NET Entity Framework and updated ASP.NET support for Silverlight.

 blog it

Dynamic Query Reflection within Linq

clipped from www.west-wind.com
As I suggested in my comment on the last blog post - read the docs and samples...and failing that ask a question on the LINQ forums: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=123&SiteID=1

Even Anders hangs out on that forum - so you will get help if you ask a question on it. ;-)

Daniel Moth has a good pointer to some LINQ samples you can use: http://www.danielmoth.com/Blog/2007/08/linq-samples.html One of these LINQ samples is called "DynamicQuery", and it provides a useful library that enables you to write dynamic LINQ expressions that enable you to accomplish what you are after above.

For example, you could write:

var query =
db.Customers.
Where("City = @0 and Orders.Count >= @1", "London", 10).
OrderBy("CompanyName").
Select("new(CompanyName as Name, Phone)");
 blog it

Dynamic Query Reflection within Linq

clipped from www.west-wind.com
As I suggested in my comment on the last blog post - read the docs and samples...and failing that ask a question on the LINQ forums: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=123&SiteID=1

Even Anders hangs out on that forum - so you will get help if you ask a question on it. ;-)

Daniel Moth has a good pointer to some LINQ samples you can use: http://www.danielmoth.com/Blog/2007/08/linq-samples.html One of these LINQ samples is called "DynamicQuery", and it provides a useful library that enables you to write dynamic LINQ expressions that enable you to accomplish what you are after above.

For example, you could write:

var query =
db.Customers.
Where("City = @0 and Orders.Count >= @1", "London", 10).
OrderBy("CompanyName").
Select("new(CompanyName as Name, Phone)");
 blog it

Lambda Expression for C# 3.0

"A lambda is an inline expression or statement block with a concise syntax that can be used in C# 3.0 and later wherever a delegate type is expected" . In a certain way we can consider Lambda Expressions as an evolution of the anonymous methods.

Look the examples below, at first sight the syntax looks very weird but when you know how they are built and you get used, you will see that it's extremely easy.

x => x + 1

x => { return x + 1; }

(x, y) => x == y

(int x, int y) => x * y

() => ExecuteAnyMethod();

Maybe you already noticed that a lambda consist of a list of input parameters, the operator "=>" (goes to) and a expression or statement. In the form of:


(input parameters) => Expression or Statement.


The list of parameters is optional, and you don't need to specify the types of the parameters in the cases where the type can be inferred. Parenthesis are also optional when we only specify one parameter.

 blog it

.NET quiz for geeks

clipped from www.ayende.com

Scot Hanselman has a list of question that you would interview a .Net candidate with. Here are my answers (without using MSDN/Google/Help/etc, just my head):

There are 102 questions, I couldn't answer 20 of them (19.6%), (you judge if I was correct or not).

I'm weak in ASP.Net & Xml, but that is no surprise to me.

 blog it