What is OfType operator in LINQ?

OfType operator in LINQ

OfType operator is used to return objects of a certain type. For example if we have an array of objects which contains strings, decimal, float and numbers or any other. We can use OfType operator to extract only strings or any particular type of values.

Here is an example to fetch the string values from an array of objects. See below,

private void Form1_Load(object sender, EventArgs e)
object[] values = {"test1",45,'c',"test2",34.67,12/12/2009,"test3",4.0,4.4f};
var strings = values.OfType();
int top = 10;
foreach (var s in strings)
Label lbl = new Label();
lbl.Top = top;
top = top + 30;
lbl.Text = s;

You just copy the above code in to Form_Load and run the solution. There will be shown the string values.


How to disable the Win Form’s Close Button ?

Disable the Win Form’s Close Button using C#

Here is the simple way to disable the Form’s close button. Just copy the following code in your code behind. Then run the form, surely the close button would be disabled.

private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
return myCp;

That's it...


Differences between XBAP, WPF Standalone and Silverlight

Differences between XBAP, WPF Standalone and Silverlight

WPF applications are divided into two categories.

• Standalone WPF Application
• XAML browser applications (XBAPs)

There is always a confusion between WPF, XBAP and Silverlight. Developers get confused which one to go for while designing a project. Here I will explain all the 3 technologies with the differences

Standalone WPF Application

- WPF applications are installed on end user's machine.

- Appear in Start Menu and Add/Remove Programs.

- Applications can be installed via MSI or ClickOnce.

- User can be offline and use the application. There is no need for Internet connection.

- Newer versions of the application may not be automatically installed in user's machine.

- WPF standalone applications can use WCF for communication.

- Applications run in its own window as other windows applications.

XAML Browser Application(XBAP)

- These type of applications are not installed in user's machine.

- They do not appear in the in Start Menu or Add/Remove Programs.

- Applications can be automatically deployed via ClickOnce.

- Applications are hosted in the browser process.

- Can be run only in IE and Firefox.

- Newer versions are always installed automatically into the user's machine.

- User must be online to use the application.

- XBAP is Windows only. We can run the application in Windows operating system only.

- XBAPs cannot use WCF.

- The user machine should have .NET framework 3.0 components.


- XBAP is IE and Firefox only. But Silverlight can run in any browser and platform.

- Silverlight is used for creating rich UI web application.

- User's machine don't need .NET framework.

- Can be embedded in HTML markup and rendered in any browser using the silverlight plug in.

- XABP has 99% features of WPF. But Silverlight is just a subset of WPF.


XBAP - Windows Presentation Foundation XAML Browser Applications

XBAP - Windows Presentation Foundation XAML Browser Applications

XBAP – XAML Browser Application is a new windows technology used for creating Rich Internet Applications. It is used for creating heavyweight .Net applications.

XAML Browser Applications combines features of both Web applications and rich-client applications. While windows applications are normally compiled to an .exe file, browser applications are compiled to an extension .xbap and can be run inside Internet Explorer.

Like Web applications, XBAPs can be published to a Web server and launched from Internet Explorer. Like rich-client applications, XBAPs can take advantage of the capabilities of WPF. Developing XBAPs is also similar to rich-client development.

Implementing a XAML Browser Application (XBAP)

The simplest way to create a new XBAP project is with Microsoft Visual Studio:

1. On the File menu, point to New, and then click Project.
2. In the New Project dialog box, in the Project types pane, choose either Visual Basic or Visual
C#. In the Templates pane, click WPF Browser Application.
3. Assign a project name and click OK to create the new project.

The WPF Browser Application project template creates an XBAP application project that includes the following:

• An application definition, Application.xaml.
• A page, Page1.xaml.

You can add to those as required.

If you prefer developing with tools that require command-line compilation.

When you run an XBAP, it is launched in a browser window instead of a standalone window. When you debug an XBAP from Visual Studio, the application runs with Internet zone permission and will consequently throw security exceptions if those permissions are exceeded.

Deploying a XAML Browser Application

When you build a XBAP, the Microsoft build engine (MSBuild) produces the following three files as a minimum:

• An executable file. This contains the compiled code and has an .exe extension.
• An application manifest. This contains metadata associated with the application and has a
.manifest extension.
• A deployment manifest. This file contains the information that ClickOnce uses to deploy the
application and has an .xbap extension.

You publish XBAPs to a Web server (Microsoft Internet Information Services (IIS) or later). You do not need to install .NET Framework on the Web server, but you do need to register the WPF Multipurpose Internet Mail Extensions (MIME) types and file extensions.

To prepare your XBAP for deployment, copy the .exe and the associated manifests to your Web server. Create a hyperlink on a Web page to navigate to the deployment manifest. When the user clicks the link and navigates to the .xbap file, ClickOnce automatically handles the mechanics of downloading and launching the application.


1. http://msdn.microsoft.com/en-us/library/aa970060.aspx
2. http://aspalliance.com/1824_Introduction_to_XAML_Browser_Applications_XBAP.1