Tag: .net

asp.net database application with ajax

In this tutorial, we will develop a complete asp.net web application with database functionality. We will also add ajax functionality in our application. CREATION OF DATABASE We create the internal database file with the visual studio. The database file is placed in the same application folder. The following are database tables: Database Name: mydb.mdf person CREATE

lambda expression with parameters

If there is a single parameter for lambda expression, just name of the parameter is sufficient as shown in below example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication10 { class Program { static void Main(string args) { Func<string, string> oneParam = s => String.Format("change uppercase {0}", s.ToUpper()); Console.WriteLine(oneParam("test")); } }

lambda expressions

Lambda expressions allow us to reduce the code, thereby reducing the complexity of the code. Here is an example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication10 { class Program { static void Main(string args) { Func<string, string> lambda = param => { return param + " XYZ "; }; Func<string,

declaring a delegate array

We can also declare a delegate array. However, each element of the delegate array must be of same signature in terms of input arguments and return types. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication10 { class Program { delegate double DoubleOp(double x); static void Main(string args) { /* DoubleOp operations

delegate with multiple arguments

We can also declare a delegate to receive multiple arguments using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication10 { class Program { delegate double GetInt(int num); delegate void ShowInt(int num); delegate void MultipleArguments(int num1, int num2); static void Main(string args) { GetInt mydelegate = Program.getValue; double ans = mydelegate(45); Console.WriteLine(ans); ShowInt

delegate static and instance methods

We can use delegate for static and non static methods, as shown in the following example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication10 { struct Currency { public uint Dollars; public ushort Cents; public Currency(uint dollars, ushort cents) { this.Dollars = dollars; this.Cents = cents; } public override string ToString()

implict – explicit type casting

Using operator overloading, we can also perform impliclit/explicit type casting. For example, in the following program, we are going to type cast Currency class object into dollars and cents, and from dollars and cents to Currency. REMEMBER: When converting from user defined type to primitive type, we use “implicit” overloading and conversion, whereas when converting

matrices computations using operator overloading

The following example shows the computations of matrices using operator overloading: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication8 { class Matrix { int[,] matrix; public Matrix() { } public Matrix(int[,] matrix) { this.matrix = matrix; } public void ShowMatrix() { Console.WriteLine(); for(int i=0; i<matrix.GetLength(0); i++) { for(int j=0; j<matrix.GetLength(1); j++)

user defined casts

We can convert from one data type to another. If we convert from a higher capacity data type to lower capacity datatype, the data loss will occur and this usually goes unnoticed. Therefore, it is always recommended to perform conversion under checked {} blocked, as in the following example: using System; using System.Collections.Generic; using System.Linq;

operator overloading simple example

The operator overloading allows the operators e.g., +, -, /, *, etc to operate on operands of non primitive/basic data types, such as int, float, double, etc. The following example explains operator overloading: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication8 { class Money { public int money; public int MoneySum