When i ran .exe file in terminal by command --> mono ToDoList.exe del 1
I got exception -->Sharing violation on path /home/puneet/Desktop/Puneet.txt
Can anyone tell me about the cause of this exception? I don't understand why i am not able to convert args[1] into integer? Thanks in advance . . . . .


using System;
using System.IO;
namespace ToDoList
{
class MainClass
{
public static void Main (string[] args)
{
try
{
int count = 0;
if(args.Length == 0)
{
string[] contents = File.ReadAllText("Puneet.txt").Split('\n');
foreach(string item in contents)
{
Console.WriteLine("{0}: {1}",count,item);
++count;
}
}
else
{
switch(args[0].ToLower())
{
case "add":
try
{
if(args.Length != 1)
{
for(int i = 1 ; i < args.Length ; ++i)
File.AppendAllText("Puneet.txt",args[i]);
Console.WriteLine("Data entered successfully");
}
else
{
Console.WriteLine("Usage : mono ToDoList.exe del/add | \"any number of arguments\"");
Console.WriteLine("To print list use : mono ToDoList.exe ");
}
}
catch
{
Console.WriteLine("Usage : mono ToDoList.exe del/add | \"any number of arguments\"");
Console.WriteLine("To print list use : mono ToDoList.exe ");
}
break;


case "del":
try
{
if(args.Length != 1)
{

string[] contents = File.ReadAllText("Puneet.txt");
File.Delete("Puneet.txt");
File.Create("Puneet.txt");
var pos = int.Parse(args[1]);
foreach(string item in contents)
{
if(pos != 0 )
File.AppendAllText("Puneet.txt",item);
--pos;
}
}
else
{

Console.WriteLine("Do you want to delete the file (Y/N)");
string ans = Console.ReadLine();
if(ans.ToLower() == "y")
File.Delete("Puneet.txt");
else
{
Console.WriteLine("Usage : mono ToDoList.exe del/add | \"any number of arguments\"");
Console.WriteLine("To print list use : mono ToDoList.exe ");
}
}
}
catch(Exception ex)
{
Console.WriteLine("Excepton encountered");
Console.WriteLine(ex.Message);
Console.WriteLine("Usage : mono ToDoList.exe del/add | \"any number of arguments\"");
Console.WriteLine("To print list use : mono ToDoList.exe ");
}
break;


default:
Console.WriteLine("Unidentified command.Command given is negleted");
break;
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}