Difference in values when converting double to integer using cast or convert

Check out the code below.

double d = 13.6;

int i1 = Convert.ToInt32(d);
int i2 = (int)d;

Continued...


Math.Round Method rounding to nearest even number

What would be the output of the following program?

 Console.Write(Math.Round(-0.5).ToString() + “~”);
 Console.Write(Math.Round(0.5).ToString()+ “~”);
 Console.Write(Math.Round(1.5).ToString()+ “~”);

 Console.Write(Math.Round(2.5).ToString()+ “~”);

Continued...


Exiting the process with the help of Enviroment.FastFail method

Have you ever had some point in code where you want to exit the application immediately? Normally for this purpose you would use the Application.Exit method.  But Microsoft has provided a better method for this purpose which not only just exits the application but also adds a message to the Windows Application event log.

The Enviroment.FastFail method takes a string as a parameter writes that value to the Windows Application Event log, creates a dump of the application and exits the process. The string passed is also included in the error reporting to Microsoft.

FastFail method should be used instead of the Application.Exit method in case the application is damaged // resource Lost etc. beyond damage and

Continued...

Convert string to uppercase when comparing after normalizing instead of lowercase

While doing string comparison after normalizing (converting both string to upper case or lower case) we should always use the upper case. Upper case is optimized for normalization.

 A small group of characters, when they are converted to lowercase, cannot make a round trip. To make a round trip means to convert the characters from one locale to another locale that represents the same character data differently, and then to accurately retrieve the original characters from the converted characters.

Converting to uppercase rather than lowercase can also prevent incorrect behavior in certain cultures. For example, in Turkish, two lowercase i's map to the same uppercase I.

Continued...


Network statistics for upload and download

Last few days while working with my broadband network (downloading few stuff) I wanted to check the exact amount of download per minute. I tried to check the data from task manager and resource monitor. But these gave data in terms of percentage of network use. Hence I could never find the exact amount of download.

So I wrote a small application to sniff the network and find out the exact amount of download. After fetching the data we can do lots of thing like creating speed chart etc…

To fetch the network we use the System.Net.NetworkInformation namespace

First we need to get the network Interface to track. A Machine might be connected to many network and we need to track each network differently. We can do that by the code

Continued...

Feature rich release of Visual Studio 2010

Visual studio 2010 has been released to RTM a few days back. This release of Visual studio 2010 comes with a big number of improvements on many fronts. In this post I will try and point out some of the major improvements in Visual Studio 2010.

1)      Visual studio IDE Improvement. Visual studio IDE has been rewritten in WPF. The look and feel of the studio has been improved for improved readability. Start page has been redesigned and template so that anyone can change the start page as they wish.

Continued...


Default printer setting using dot net
Hi,

There came a requirement in one of my colleague’s project whereby it was needed to set the printer to be used for the lotus notes (The project is about integrating with Lotus Notes.).  

To solve the issue instead of looking into the Lotus notes API I thought it should be much easy to set the default printer for the machine. Once the Default printer is set Lotus notes will use this printer to print any document.  Below is the code needed to set the default printer of any machine.

[DllImport("winspool.drv", SetLastError = true)]
private static extern

Continued...

Microsoft released the source code for Dot net Framework class library

Hi 

 

The news is out and so are the source codes of dot net framework. Microsoft has released the source code for dot net class library. This is one of the biggest news in the waiting for a long time.

 

Today ScottGu announced the release of the source code of dot net framework class library. The source are released and well integrated with the Visual studio 2008 and that even allows you to debug through the source code when you get stuck.

 

Following is the list of libraries that have

Continued...

Dot Net Framework 3.5 Namespace poster available for download

Hi,

Here s something that I found very useful on the Dot net framework3.5.  If you have just started to learn about Dot net framework 3.5 and want to know all the changes in the name space and the new namespaces includes in the framework, below is the chart showing it.

The Dot net framework poster is also available in many formats. Below are the links for the same.

Full XPS
Split XPS
Continued...


Dot Net framework 3.5 and Visual studio 2008 released by Microsoft

Hi,

News of November is here. Microsoft has released the latest version of Visual Studio 2008 and Dot net framework 3.5. If you want to use the free Visual Studio 2008 Express editions (which are much smaller and totally free), you can download them here

Although I have mentioned it before, here is a quick recap of the new features of Visual Studio 2008

Multi targeting support (supports framework 2.0, 3.0 and 3.5)

Asp.Net Ajax Support.

JavaScript  intelligence

JavaScript Debugging

VS 2008 new Web designer.

Very good support for CSS

Language Improvement and LINQ.

Data Access improvement with LINQ to SQL.

Continued...


Source code of Dot net framework released by Microsoft with VS 2008 and Dot Net Framework 3.5
Hi,

What a news from Microsoft. They have decided to provide the source code of the dot net frame work class library. The source code will be provided with the final release of the VS 2008 and Dot net framework 3.5. The source code is provided under the Microsoft reference Licence. You can read the full post here

I know we can see the code using reflector, but the ability to debug with the source code will be just great. Think how great it would be to be able to press F11 (Step Into) at the Gridview.databind() and see whats happening inside the databind method.

I am sure this will be loads of fun for most of the developer like me. Cant wait to get my hands on this one.

Vikram

Reading a MultiLine string one line at a time

Hi,

Yesterday I was working on a small page for helping one of my friends with a utility (I will update the small bit as a new Utility section in the site very soon). In the small bit of code I had to take a string convert it to a stream, and then read the stream one line each.

I was working with the stream class conversion of the stream and thought of posting the code. Here is the code for converting a string to a stream.

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

MemoryStream MStream = new MemoryStream(encoding.GetBytes(stringTobeConverted));
To read the stream one line at a time we need to convert the stream to type StreamReader
Continued...
            

Visual studio 2008 Windows Server 2008 and SQL Server 2008 might release in 2007

Hi,

Here is a big update on my previous Post. I found this news at the Dave’s Blog and thought of sharing it.

The date 27 Feb 2008 has been kept for the release of the three big products (Visual studio 2008 Windows Server 2008 and SQL Server 2008). This does not mean it will release on the same day. The release might be before that. According to the blog Microsoft is trying to make the release today itself. 

Thanks
Vikram


List of command Line FTP commands in windows

Hi,

A few days back, I was working with some FTP command. Then I realized that many people had asked me to provide some help on the FTP commands. Hence I decided to write a post on some of the common FTP commands for windows with their small explanation.

append - Appends a local file to a file on the remote computer.
ascii - Sets the file transfer type to ASCII, the default.
bell - Toggles a bell to ring after each file transfer command is completed (default = OFF).
binary - Sets the file transfer type to binary.
bye - Ends the FTP session and exits ftp.
Continued...


27 Feb 2008 scheduled for the release of Visual studio 2008 Windows Server 2008 and SQL Server 2008

Hi

Mark the day 27 February 2007 in your calendar. If you are a dot net developer then this is one of the biggest day for you. Three of the major products to be launched in one day. It’s unbelievable. Windows Server 2008, Visual studio 2008 and Microsoft SQL Server 2008 all being scheduled to launch in one day. 

Thanks
Vikram

P.S. Also start hoping that they get it right and dont delay this release.


Difference between String.Empty, Empty Quotes and String.length

Hi

A few days back when I was working with string. At many point of time I had to make a checking for empty string. I started thinking about the difference between “” and string.empty. and which one is a better way to check if the string is empty or not.

The difference between string.Empty and “” is very small. String.empty will not create any object while “” will create a new object in the memory for the checking. Hence string.empty is better in memory management.

But the comparison with string.length == 0 will be even faster and the better way to check for the empty string. And I also have a bias for checking with string.length in this case. But do not forget to make a checking for null value if you are also expecting null value in the comparison.

Happy coding
Vikram

 
Copyright © 2006 - 2012 Vikram Lakhotia