Skip to main content

Posts

Const and Readonly keyword

Both these words play a very important role in defining constants in an application (C#). At one sight, it seems like, both are same but exactly it is not he case. Let's understand one by one to get the clear picture. The word const itself means, it will never change. If you are specifying any variable as a  const t hat means the value of the variable is never going to change inside the application. How we declare a constant is, by using a  const  keyword. Basically, one can define  const  only on the primitive types, like int, double, etc. One should make sure that the value should be assigned at the time of declaration itself and another important thing is whatever value is set for  const  variable, that value will be set at the compile time itself and this value will get stored inside a .dll or an .exe. In later part, I'll show u on how we can see this value inside a dll or an exe using an Ildasm. Sample code to define  const   variable is as: Another key

Silly but useful stuff - Part 2 (ASP.Net)

Using StartMode Attribute Every time we update our site, IIS must recompile it during the first request, so the initial request takes significantly longer than subsequent ones. An easy solution for this is to tell IIS to automatically recompile our site as part of the update process. And this can be achieved using the startMode attribute in the ApplicationHost.config file. In essence, we can say, by using startMode attribe, one can reduce the initial load time of an ASP.Net site. Hope it helps :)

Silly but useful stuff - Part 1 (.Net)

Collection and List Let's have a look at this snippet: In first sight, most of you might feel that both List and Collection will contain print numbers from 1 to 6. Am I right? But Alas! There is a hidden gotcha in it ;) Because the actual output is: What happen surprised??? If you have ever tried to get in depth of Collection and List, then you might know the answer. Well, the answer is pretty simple. MSDNdocumentation clearly states that "Initializes a new instance of the Collection class as a wrapper for the specified list" . And on the other hand, MSDN documentation states that "Initializes a new instance of the List<T> class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied." Hope now it is clear to you. So, the moral of the story is, one should be very cautious while using L

Converting a given string to Title Case

To convert string in title case is bit tedious and may require lot of code as there is no direct method available in C#.Net  in String class. So, here I am sharing a method, which will be the extension method for String class and can be used to convert given string to title case. Here I am using CultureInfo from Globalization and ToTitleCase method of TextInfo class. public static class StringExtensions {     public static string ConvertToTitleCase(this string input)     {         System.Globalization.CultureInfo cultureInfo =         System.Threading.Thread.CurrentThread.CurrentCulture;         System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;         return textInfo.ToTitleCase(input.ToLower());     } } Hope reusing this will save lot of your time :)

Changes in Visual Studio 2012

Introduction Nowadays, we see that software development process is shifting from enterprise-driven process to consumer-focused approach, in which applications are fully based on the taste of consumer market and the devices they want to use. And the speed at which these devices and platform are emerging, it is becoming more and more challenging for developers. Earlier applications were used to run on a server or a desktop but today many more devices like smartphones, tablets are becoming ubiquitous. So, in this case developer must either create applications that work on multiple platforms or make applications tailored to each platform with similar logic and the most important thing is, there should be a connected experience that allow user to seamlessly move among all these devices and platforms. But as long as Microsoft is with developers, developers need not worry. Agree ???  Visual Studio 2012   Launch of  Visual Studio 2012  solved a lot of problems. Now instead of the de

Windows App Splash Screen - Beginners Tutorial

I ntroduction Continuing to my previous article title, here we will see about splash screens, how to set the splash screen image and how to change the background color.  Splash Screen Every Windows Store app must have splash screen. Splash screen consists of image and a background color. Whenever the user will launch application, splash screen will be the first to come up. Now you might be thinking, what is the purpose of splash screen??? We all know that, whenever any application is launched, lot many things happened at backend before our application is fully launched. So, splash screen provides a way to hide all those background details from the user. This splash screen is launched, when application is initialized and as soon as our application is ready for interaction, this splash screen goes off. Isn't it a nice thing ? Now question is can we customize this splash screen ? Then my answer will be Yes. You can customize image as well as background color. Enough of th

Creating Windows Store app - Beginners tutorial

I ntroduction In this tutorial we will be creating a very basic Windows Store App using XAML and C#. As this is the very first tutorial of this series, I'll be focusing mainly on project setup and basic workflows and later on, in other upcoming series, I'll be picking up more advance concepts. So, before moving forward, let's talk about the environment setup to execute our app. Pre-requisite In order to complete Windows 8 metro style app, our machine need following things: You need Windows 8 with Microsoft Visual Studio Express 2012 You need developer license  Creating a project Launch Visual Studio 2012. Select File >> New Project. The New Project dialog window appears and from the left pane you can select template of your choice In the left panel, you can select 'Windows Store' template. Once selected, center pane will show you the list of available items for the selected template. Here we are using  Blank App