Search

Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Nov 20, 2008

C# ?? operator

I just found one beautiful operator of C#, which is ?? Its more compact then ternary operator [?:]. Ternary operator is short form of if-else and ?? is also kind of if else, but its work with null value an one assumption. lets see how it works. Its always case when we have to check for null condition, like query string check or Session value check, here how we do to check null for query string.

string strUserId = null;

//Using if-else
if (Request["uid"] == null)
strUserId = string.Empty;
else
strUserId = Request["uid"];

//Using ternary operator
strUserId = Request["uid"] == null ? string.Empty : Request["uid"];

now lets use ?? operator

//Using ?? operator
strUserId = Request["uid"] ?? string.Empty;

Isn't it handy? What is does is, it check only for null, it it found left side null then return the value form right hand else it returns left hand site value itself. In our case if there is no uid in query string then will return empty string or else will return the value of uid from query string.

Sep 14, 2008

Why doesn't C# support multiple inheritance?

Hi all,

I was always searching for the answer of "Why doesn't C# support multiple inheritance?".

After some googling I found the answer from MSDN.

Please have a look at the link.

Apr 28, 2008

Delegates and Events in C# / .NET

I come accross a good link for how Delegates and Events works in C#.

What are delegats, what is multicast-delegate handling events with delegates... all this with simple and understandable example.

Read more Delegates and Events in C# / .NET

Sep 20, 2007

Threading in C#

C# supports parallel execution of code through multithreading. A thread is an independent execution path, able to run simultaneously with other threads.

To know how its working, when to use thread etc. have a look at 'delicios'

Jun 14, 2007

Create .NET documentation with Microsoft's Sandcastle

Hello all,

This is post for developers who are using xml comments.

The .NET Framework allowed C# developers to use XML-style comments in their code. This feature was added to VB.NET with version 2.0. The compiler can use these comments to generate basic technical documentation. The end result of using the XML commenting feature is a large XML file that is less than user friendly

How to get Sandcastle



The latest version of Sandcastle is available via href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E82EA71D-DA89-42EE-A715-696E3A4873B2&displaylang=en">Microsoft's
March 2007 Community Technology Preview
. You may install and run it on
Windows Server 2003 or Windows XP Service Pack 2. It requires the href="http://msdn2.microsoft.com/en-us/netframework/aa731542.aspx
">.NET
Framework 2.0
, as well as the href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.asp">HTML
Help Workshop
. Once the prerequisite software is installed, you can install
the Sandcastle tool.



I also have delicious Create .NET documentation with Microsoft's Sandcastle .

Jun 1, 2007

Cannot convert null to 'int' because it is a value type

Hello friends,

I found solution for the following error:

Cannot convert null to 'int' because it is a value type

when i wrote

int i = null

Now we can assign null values to such value types viz. int, datetime, float...

Check out Nullable Types

Feb 28, 2007

Formating output in C#

Hello,

I come across blog which is very useful to format our output using string.Format() in C#

http://blog.stevex.net/index.php/string-formatting-in-csharp/

I have delicious on C#

Feb 21, 2007

Problem after converting Vb.net to C#

Hello,

I was converting my vb project to C# using converter. This tool is really helpful to me for converting my vb application.

It converts successfully, but i notice some points that needs to be checked after done conversion

· Ensure that each page must have C# as language
· Container.DataItem("Field") must converted to DataBinder.Eval(Container.DataItem,"Field")
· Check for the inline code