Showing posts with the label C#

Free E-book: Time-Saving VS11 and ASP.NET 4.5 Features You Shouldn’t Miss

Last weak, two Telerikers Joshua Holt and Carl Bergenhem introduced a very nice free e-book for developer community to get job done quickly with less code. Very nice book, read it once.

Creating PDF Files in ASP.NET using iTextSharp

iText is a library that allows you to create and manipulate PDF documents. It enables developers looking to enhance web and other applications with dynamic PDF document generation and/or manipulation.

Facebook Groups for Technical Discussions by Abhimanyu Kumar Vatsa

Friends, I am running 3 Facebook Groups for all our technical discussions. You can share the blog links or ask your technical difficulties or even share your views about technology etc. Please join the group and start exploring technologies. Windows Phone (WP) ASP.NET MVC C# Thanks.

Definite Assignment Rule in C#

Introduction In the programming languages like C and C++, we define any variable and accidentally used it as information before giving any value. C and C++ languages have no such in-built feature which can recognize it but C# does not allow us to use an unassigned variable this rule is known as Definite Assignment Rule. We must assign a value to a variable before use it; otherwise we will get a 'compile-time' error. Consider in C++ Language Let's take a look at example given below in C++ Language, it has a main method having an unassigned variable named 'sampleValue' but when we run this, no error comes out. Even this display some value say it as default value. Try by assigning some value in variable 'sampleValue' and look at output, its changed (overwrite) by newer one. Look at image below. Consider in C# Language Let's take a look at example given below in C# Language, it has a main method having an unassigned variable named '

Exception/Error Handling in C# - Part 1

Introduction In programming, exceptions/errors can happen (appear) at any time and by using traditional techniques to manually add error-detecting code around every statement is cumbersome, time consuming. C# makes it easy to separate the error-handling code from the code that implements the main flow of the program by using exceptions and exception handlers. To write exception aware programs, we need to do two things: (i) By placing statements inside a try block All statements placed inside try block are executed and if none of the exception appears, run all codes one by one till end. If any error condition appears, execution jumps out from try block in catch block. (ii) By using one or more catch handlers If anyone statement in try block generates exception, then runtime examines the appropriate catch handler and jumps to that. Example             try             {                 //statements             }             catch ( OverflowException

Optional and Named Arguments in C#

Introduction One of the new interesting features in Visual Studio 2010 is 'Named and Optional' arguments. Practically, they are very useful together but both are quite different. Optional Arguments Optional Arguments enable us to omit arguments for some parameters. Any call must provide arguments for all required parameters but can omit arguments for optional parameters. The parameter which is omitted has default value as part of its definition. If no argument is sent for that the default value automatically will be used. Optional parameters are defined at the end of the parameter list after any required parameters. In above example, we are not sending the value for 'width' parameter because it is Optional. If you try to send the 'width' parameter value then it will overwrite existed value. For example: In above example, width value will be replaced by 6. Named Arguments Named Arguments enable us to specify an argument for a particular par

is and as Operator in C#

Introduction Look at the example given below, Circle c = new Circle(32); object o = c; int i = (int)o;          // it compiles okay but throws an exception at runtime Here runtime is more suspicious, if the type of object in memory does not match the cast, the runtime will throw an InvalidCastException. We should be prepared to catch this exception and handle it appropriately if it occurs. However, catching an exception and attempting to recover in the event that the type of an object is not what we expected it to be is a rather cumbersome approach. C# provides two more very useful operators that can help us to perform casting in a much more elegant manner by using is and as operators. Let's have some talk on is and as operators too. is Operator is operator is used to check whether the run-time type of an object is compatible with a given type or not. In other word, we use is operator to verify that the type of an object is what we expect it to be. Let

Strings in C# - Part 2

Introduction   String (string) is an alias type of the System.String class. This class provides a set of methods for working with strings. Let's list some of them that we will cover in this article. PadLeft()/PadRight(): Returns copies of the current string that has been padded with specific data. Remove()/Replace(): Receives copy of string with modifications. Deletes a specified number of characters from this instance beginning at a specified position. Split(): Separates strings by a specified set of characters and places these strings into an array of strings. Trim(): Trim method removes white spaces from the beginning and end of a string. TrimStart(): Selectively removes a series of characters from the starting position. TrimEnd(): Remove all trailing punctuations from string. Substring(): Returns a string that represents a substring of the current string. ToCharArray(): Returns a character array representing the current string. Let's discuss

Popular posts from this blog

Lambda two tables and three tables inner join code samples