Monday, 31 December 2018

Monday, 3 December 2018

Sum (LINQ)

Sum (LINQ)

Enumerable.Sum is extension method from System.Linq namespace. It returns sum of numeric values in collection.

Sum for Numeric Types

Gets sum of values from list of integer numbers.
Gets sum of values from list of decimal numbers.
Calling Sum on empty collection returns 0.

Sum for Nullable Numeric Types

Gets sum of values from list of nullable integers.
Returns 0 if the collection contains only null values.
Returns 0 if the collection is empty.

Sum with Selector

This example sums lengths of all strings in the list.

Sum with Query Syntax

LINQ query expression to get sum of numeric values in the collection.
LINQ query expression to get sum of numbers which match specified predicate.
LINQ query expression to get sum of string lengths using selector.

IQS


  1. Singleton

  1. public sealed class Singleton  
  2. {  
  3.     Singleton()  
  4.     {  
  5.     }  
  6.     private static readonly object padlock = new object();  
  7.     private static Singleton instance = null;  
  8.     public static Singleton Instance  
  9.     {  
  10.         get  
  11.         {  
  12.             if (instance == null)  
  13.             {  
  14.                 lock (padlock)  
  15.                 {  
  16.                     if (instance == null)  
  17.                     {  
  18.                         instance = new Singleton();  
  19.                     }  
  20.                 }  
  21.             }  
  22.             return instance;  
  23.         }  
  24.     }  
  25. }
1)      How to List out Even Numbers sum from a List of Integers using LINQ
var LstACValues = new List<int> { 1, 7, 2, 5, 10};

            var result = (from m in LstACValues
                          where m % 2 == 0
                          select m).ToList().Sum();  
2)      What type of information has application object in asp.net c#

What is an application object?

Application object is used to store the information and access variables from any page in application. Application object is same as session object only the difference is session object is used to maintain the session for particular user. If one user enters in to the application then session id will create for that particular user if he leaves from the application then the session id will deleted. If they again enter in to the application they will get different session id but application object is same for all users once application object is created that application object is used throughout the application regardless of user. The information stored in application object accessed throughout all the pages in application (like database connection information) and we can change the application object in one place those changes automatically reflected in all the pages.


Y create application objects in Global.asax file and access those variables throughout the application. 

T      know about how to add Global.asax file 


<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["UserID"] = "SureshDasari";
}
</script>

A following code in Global.asax file like this
public void Page_Load(object sender, EventArgs e)
{
this.lblText.Text =  "UserName: " + Application["UserID"] + "<br>";
}

3)      How to call Connection string from application.
Ø  string connectionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;

4)      When the class library build what files generated
Ø  Two Files generated
1)      .DLL
2)      .PDB