Sunday, 22 May 2016

Difference Between Generic and Collections in C#


Difference Between Array - Generic - Collections in Csharp

Array :

An Array is Fixed Size Data Type . For Storing data in Array you need to define the size of array and Also Type of Array ( int, string , float etc )

Depending on Memory Allocation Data Types are of Two Types -

  • Value Type 
  • Reference Type 

See Difference Between Value Type and Reference Type in Link Below - 
http://geeksprogrammings.blogspot.in/2015/09/value-types-vs-reference-types-dotnet.html

Array is a Value Type that needs to define its size in order to allocate space to it in memory . This is little problem with array as sometimes we need Dynamic Size to store large number of values

Collections :
Collections are Defined in System.Collections Namespace . Collections Are Variable Sized . We Can add / remove items from collection with any restriction of defining size and type of data

Example :- Arraylist are Collections .

Logically Collections are Referency Types . Now Question is Why Collections are Referencec Types ?

Collections are of Variables Sized So Whenever Some Type is Variable Sized It needs to be stored in head instead of Memory Stack give to application . and poiter to that heap is set in the top of stack . it is stored in heap because main memory is valuable and we don't exactly know that How much size variable sized Collection will take so it is allocated disk space as heap instead of storing it directly in main memory Pointer to heap location is set to top of stack so whenever we require it we can use that pointer to get / set that value .

See Difference Between Value Type and Reference Type ( Stack & Heap ) in Link Below - 
http://geeksprogrammings.blogspot.in/2015/09/value-types-vs-reference-types-dotnet.html

Example of Collections - 

ArrayList arrList = new ArrayList();
arrList.Add(007);
arrList.Add("Heemanshu Bhalla");
arrList.Add(DateTime.Now);

If we want to loop that arrList then we can do it as below -

foreach (object o in arrList)
{

}

But there is one problem we always need to parse each element in collection using object as we don't know the type of data that it contains and that could create problem on runtime

Problem With Collections & Evolution of Generics

Generic Types Solves This problem check Generic Types Below  -

Generic Types :
Generic Types Contained in System.Collections.Generic Namespace . It removes the problem of Unknown Data types exist in Collections

Generic List ( List <T> ) , Here T means datatype that could be Int , String , DateTime etc . So We can define the type of data that we want to store and we can also parse the data simple as type is already known . SO it is Type Safe . If you Create Int Generic List or Generic Type and try to store some different type then it will give compilation Error and does not allow you to store data of Another Type that is not allowed .

Example of Generic List below - 

List<string> lstString = new List<string>();
lstString.Add("Heemanshu Bhalla");
lstString.Add("I am A Geek");

List<int> lstInt = new List<int>();
lstInt.Add(007);
lstInt.Add(786);

Saturday, 21 May 2016

Convert Date Format To dd/mm/yy in Sql Server


If you Mssql Server is Using Some Other Date Format For Insert Date in Date Column Then Possibly Default Date format is set to US Date Format ( mm/dd/yy ) and if you want to insert date in dd/mm/yy . In order to insert date in this format you need to set Date Format to French / British ( dd/mm/yy )

So first I recommend you to Use any of Jquery Date Picker and pass the selected date / datetime as below to Insert Query as Below -

insert Table_Name (Date_Column)  values (convert(datetime,'18-06-12 10:34:09 PM',103));

Here second parameter 103 is For French Date Format dd/mm/yyyy .If you want to have dd/mm/yy then use 3 in that parameter

Different Types of Date Format Code as As Below - 

Without century (yy) (1)With century (yyyy)StandardInput/Output (3)
-0 or 100 (1,2)Default for datetime and smalldatetimemon dd yyyy hh:miAM (or PM)
1101U.S.1 = mm/dd/yy

101 = mm/dd/yyyy
2102ANSI2 = yy.mm.dd

102 = yyyy.mm.dd
3103British/French3 = dd/mm/yy

103 = dd/mm/yyyy
4104German4 = dd.mm.yy

104 = dd.mm.yyyy
5105Italian5 = dd-mm-yy

105 = dd-mm-yyyy
6106 (1)-6 = dd mon yy

106 = dd mon yyyy
7107 (1)-7 = Mon dd, yy

107 = Mon dd, yyyy
8108-hh:mi:ss
-9 or 109 (1,2)Default + millisecondsmon dd yyyy hh:mi:ss:mmmAM (or PM)
10110USA10 = mm-dd-yy

110 = mm-dd-yyyy
11111JAPAN11 = yy/mm/dd

111 = yyyy/mm/dd
12112ISO12 = yymmdd

112 = yyyymmdd
-13 or 113(1,2)Europe default + millisecondsdd mon yyyy hh:mi:ss:mmm(24h)
14114-hh:mi:ss:mmm(24h)
-20 or 120 (2)ODBC canonicalyyyy-mm-dd hh:mi:ss(24h)
-21 or 121 (2)ODBC canonical (with milliseconds) default for time, date, datetime2, and datetimeoffsetyyyy-mm-dd hh:mi:ss.mmm(24h)
-126 (4)ISO8601yyyy-mm-ddThh:mi:ss.mmm (no spaces)

Note: When the value for milliseconds (mmm) is 0, the millisecond value is not displayed. For example, the value '2012-11-07T18:26:20.000 is displayed as '2012-11-07T18:26:20'.
-127(6, 7)ISO8601 with time zone Z.yyyy-mm-ddThh:mi:ss.mmmZ (no spaces)

Note: When the value for milliseconds (mmm) is 0, the milliseconds value is not displayed. For example, the value '2012-11-07T18:26:20.000 is displayed as '2012-11-07T18:26:20'.
-130 (1,2)Hijri (5)dd mon yyyy hh:mi:ss:mmmAM

In this style, mon represents a multi-token Hijri unicode representation of the full month's name. This value will not render correctly on a default US installation of SSMS.
-131 (2)Hijri (5)dd/mm/yyyy hh:mi:ss:mmmAM

Evolution of Javascript To Jquery To AngularJS


Today’s starting programmers mostly directly dive into Jquery / angularjs , Programmers of last decade started with javascript . and Now Angularjs is on hike .

See whenever a WebPage is opened , JS / Jquery / AngularJS Code is on Client Side So Amount of Code is adds to Page will Increase Request Time .

We Use Javascript Before Jquery , Different types of Sliders , Dom Manipulations were done with lot of Javascript code like using But After Jquery We took a Relief for many things as below
Lines of Code Decides Lifeline of App as below -

Javascript -
Function changeBachground(color) {
  Document.body.style.background = color;
}
Onload=”changeBackground (‘red’);”

Jquery 
$ (‘body’) .css (‘background’, ‘#ccc’);

So Simple if we can achieve something easily with less code why we will not adopt it 
Then AngularJS Came that is a complete MVC Framework . It is also Javascript Framework . So whatever you do with AngularJS you can also achieve with Javascript . But Why you need to it start it from scratch you can join angularjs repository to propose some solid changes to it and extend it if you strongly need as doing everything you need to do in a website using javascript doesn’t look good idea .

JAVASCRIPT CODE

Characters: 700

Lines of JavaScript: 13
<!DOCTYPE html>
<html>
  <body>
    <h1>Hello World with pure JavaScript</h1>
    Write some text in textbox:
    <input id="hello-input" type="text" />
    <h2 id="hello-output">Hello </h2>

    <script>
      var inputField = document.getElementById('hello-input');
      var label = document.getElementById('hello-output');

      var handleKeyup = function() {
        var value = inputField.value;
        label.innerHTML = 'Hello ' + value;
      }

      if (document.addEventListener) {
        document.addEventListener('keyup', handleKeyup);
      } else if (document.attachEvent) {
        document.attachEvent('keyup', handleKeyup);
      }
    </script>
  </body>
</html>

JQUERY

Characters: 529
Lines of JavaScript: 7
<!DOCTYPE html>
<html>
  <body>
    <h1>Hello World with jQuery</h1>
    Write some text in textbox:
    <input id="hello-input" type="text" />
    <h2 id="hello-output">Hello </h2>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script>
      var inputField = $('#hello-input');
      var label = $('#hello-output');

      inputField.on('keyup', function() {
        var value = inputField.val();
        label.html('Hello ' + value);
      });
    </script>
  </body>
</html>

ANGULARJS

Characters: 325
Lines of JavaScript: 0
<!DOCTYPE html>
<html ng-app>
  <body>
    <h1>Hello World with AngularJS</h1>
    Write some text in textbox:
    <input type="text" ng-model="sometext" />
    <h2>Hello {{sometext}}</h2>

    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
  </body>
</html>

Wednesday, 18 May 2016

Namotel : Make In India Failed Again


The Story of Freedom 251 is not so old and Now Again Make In India Came With a New Crappy Thing "Namotel"  . We know Namo is rocking these days in Indian Politics But that does not mean its name works everywhere . If you are doing Shit then It will not come in different way if you say NAMO .

Namo + tel  = Website Crash

Namotel is another attempt of "Make In India" To Lauch & Offer Chepest SmartPhone . The Crappy game started by Freedom 251 gave to birth to another one . This Time SmartPhone is offered at Price of "Rs 99" It is claimed to be India's Most Affordable Smartphone

In Press Conference Company's Promoter Madhav Reddy Said Smartphone will be available to be booked at Price of Rs99 from 17 May,2016 To 25 may, 2016 On Company's Official Website Namotel . Smart Phone Will Be Available on Cash On Delivery

But I think they Don't Know How To Launch A Product To 1.252 Billion Indians . This Also Doubt About the Quality of Make In India Products That they are planning To launch and also Some That they launched .

Instead of Launching Cheap SmartPhone they should Use Their Talendted People To Make Valuable , Creative and Better Quality Product Atleast Better Than Freedom 251 or Nametel

Message By Comapany That Didn't Stood Up For Even 1 Day

 'Joy and freedom represents the logo! The same joy will flourish in billion Indians in the form of smart Connect with (3 different looks and shapes) Android Smart powerful Phone at 99. We make this product to show love for India it is a 'MAKE IN INDIA' Initiative. This model is limited and it is applicable only for India and who holds Aadhar Identity.'

Namotel Rs. 99 SmartPhone Product Specification


  • 4-inch display with 480x800 pixels WVGA resolution.
  • Android 5.1 Lollipop OS 
  • 1GB RAM. 
  • 4GB of internal storage which is expandable up to 32GB via microSD card.
  • 2MP camera at the back and a VGA selfie camera
  • Connectivity options include 3G and dual-SIM.
Different Namotel Products







COMPANY WEBSITE BELOW




Tuesday, 17 May 2016

Tempdata vs Session in Asp.net MVC


Why Sessions are Not Recommended to use in MVC

One of the Fundamental Principal of Asp.Net MVC Framework is  Web is Stateless And AspDotNet MVC is Stateless AspDotnet WebForms is a try to make Stateful Modal But Its difficult to main it as this modal does not exist . Sessions Create lot of load on Cache that was biggest problem .

Using Session in AspDotNet MVC is like Putting APPLE Logo on Asus Laptop and Calling it Apple Laptop . Reality does not change .

What Is Alternative To Session in MVC

You can use TempData in place of Session . Tempdata is limited form of Session . Don’t Use Session in MVC as you are already having Tempdata and one benefit of Using Tempdata is They will automatically deleted no need to clear or remove them as we do with session

How To Use TempData In MVC

When Data is TempData is read it is immediately market for deletion at the end of request . That means you can use Value Tempdata In Tempdata Only at the Next Request . See Example Below - 

TempData is Filled With Data

TempData["SomeTemp"]= "Hey! This is MVC" ;

Tempdata Accessed in Second Request 

Object value = TempData["SomeTemp"] ;

Value in Tempdata will be Cleared After Above Line of Code . If you access in after that line of code after above line you will not found it there it will be deleted


Keep And Peek Methods 

Peek And keep methods are used to read value without marking it for deletion after reading its value . So it is acutally helping us to retain its after its first read instead of deleting tempdata

With Peek Method We get the value of Tempdata Without Marking it For Deletion . In this method we access the Tempdata value using Peek Method That tells it to Hold Value and does not mark it for deletion

With Keep Method we hold the Value of Tempdata that was marked for Deletion after its  first read . so it is using two different calls . First one is getting Tempdata Value then Second call is To Save Tempdata From Deletion