Posts Tagged ‘C#’

Modify Collection while Iterating C#

May 10, 2017 1 comment

The general rule is that you can’t modify a collection/array/list while iterating over it.

If you are trying to modify loop while iterating you will get following error message

List strList = new List();


foreach(string str in strList)


System.InvalidOperationException: Collection was modified; 
enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at Rextester.Program.Main(String[] args)

Here is the simple solution

int listLength = strList.Count();

for(int i=0; i<listLength; i++)

//Add New Element
if(i == 0)//Some codition when you want to add new element to list/array


Hope it helps !


Set focus on textbox

November 16, 2016 Leave a comment

Using Jquery

$(function() {

Using Javascript
window.onload = function() {


Categories: ASP.NET, Code Project Tags: , , ,

File Download code in

If Not String.IsNullOrEmpty(strURL) Then
Dim req As New WebClient()
Dim response As HttpResponse = HttpContext.Current.Response
response.Buffer = True
response.AddHeader(“Content-Disposition”, “attachment;filename=””” + Server.MapPath(strURL) + “”””)
Dim data As Byte() = req.DownloadData(Server.MapPath(strURL))
End If


Hope it helps !

Full form

March 30, 2015 Leave a comment

WSDL : Web Services Description Language
REST : Representational State Transfer
SOAP : Simple Object Access Protocol

..Will add some more soon

Deep and Shallow Copying, Difference of Shallow and Deep Copying

December 16, 2014 Leave a comment

What is Shallow Copy?

Shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied.

What is Deep Copy?

A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. A deep copy occurs when an object is copied along with the objects to which it refers.

When creating copies of arrays or objects one can make a deep copy or a shallow copy. This explanation uses arrays.

Recall array variables in Java are references or pointers. A shallow copy can be made by simply copying the reference.

public class Ex{
private int[] data;

public Ex(int[] values){
data = values;

public void showData(){
System.out.println( Arrays.toString(data) );

The above code shows shallow copying. data simply refers to the same array as vals.


This can lead to unpleasant side effects if the elements of values are changed via some other reference.

public class UsesEx{
public static void main(String[] args){
int[] vals = {-5, 12, 0};
Ex e = new Ex(vals);
e.showData(); // prints out [-5, 12, 0]
vals[0] = 13;
e.showData(); // prints out [13, 12, 0]
// Very confusiin, because I didn’t intentionally change anything about the
// object e refers to.

A deep copy means actually creating a new array and copying over the values.

public class Ex{
private int[] data;

public Ex(int[] values){
data = new int[values.length];
for(int i = 0; i < data.length; i++)
data[i] = values[i];

public void showData(){
System.out.println( Arrays.toString(data) );

The above code shows deep copying.


Changes to the array values refers to will not result in changes to the array data refers to.

Gantt chart in

January 3, 2014 Leave a comment

Hello Firends,

Below I have listed some good library for Gantt chart in

Please visit again for more details like how to create customize chart report , Create dynamic chart from etc.

Hope this help!