I am making a personal assistant console application by using C#
my problem is when after selecting the condition in the loop in main method in 165th line after executing the below code the the scope of the exection should return to the 165th line until it exists.i have used goto staemnt but no luck.please help me
`
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Personal_Assistant
class Contact
{
struct details
{
public string Name;
public string Address;
public string Phone;
public string EmailID;
public string Solo;
};
private details Testdetails;
private details Apptdetails;
static FileStream F;
StreamWriter W;
StreamReader R;
public void GetContactData()
{
Console.Write("Enter Name: ");
Testdetails.Name = Console.ReadLine();
Console.Write("Enter Address: ");
Testdetails.Address = Console.ReadLine();
Console.Write("Enter Phone #: ");
Testdetails.Phone = (Console.ReadLine());
Console.Write("Enter Email Address: ");
Testdetails.EmailID = Console.ReadLine();
F = new FileStream("Contacts.txt", FileMode.Append, FileAccess.Write);
W = new StreamWriter(F);
//Writing data into the file
W.Write("Name: " + Testdetails.Name);
W.Write("?");
W.Write("Address: " + Testdetails.Address);
W.Write("?");
W.Write("Phone #: " + Testdetails.Phone);
W.Write("?");
W.Write("EmailID : " + Testdetails.EmailID);
W.WriteLine("?");
W.Flush();
W.Close();
}
public void Search_Appointment()
{
string Str, CheckStr1, CheckStr2;
string N; int Pos;
F = new FileStream("Appointment.txt", FileMode.Open, FileAccess.Read);
R = new StreamReader(F);
Console.Write("Enter name: ");
N = Console.ReadLine();
//Code to fetch data and display in proper format
while ((Str = R.ReadLine()) != null)
{
CheckStr1 = "Name: " + N;
Pos = Str.IndexOf("?");
CheckStr2 = Str.Substring(0, Pos);
if ((CheckStr1.CompareTo(CheckStr2)) == 0)
{
while (true)
{
Pos = Str.IndexOf("?");
if (Pos == -1)
break;
Console.WriteLine(Str.Substring(0, Pos));
Str = Str.Substring(Pos + 1);
}
Pos = 0;
}
}
R.Close();
}
public void GetAppointmentData()
{
Console.Write("Enter Name: ");
Apptdetails.Name = Console.ReadLine();
Console.Write("Enter Date ");
Apptdetails.Address = Console.ReadLine();
Console.Write("Enter Time: ");
Apptdetails.Phone = (Console.ReadLine());
Console.Write("Enter Location ");
Apptdetails.EmailID = Console.ReadLine();
Console.Write("Enter Duration ");
Apptdetails.Solo = Console.ReadLine();
F = new FileStream("Appointment.txt", FileMode.Append, FileAccess.Write);
W = new StreamWriter(F);
//Writing data into the file
W.Write("Name: " + Apptdetails.Name);
W.Write("?");
W.Write("Date: " + Apptdetails.Address);
W.Write("?");
W.Write("Time: " + Apptdetails.Phone);
W.Write("?");
W.Write("Location : " + Apptdetails.EmailID);
W.Write("?");
W.Write("Duration: " + Apptdetails.Solo);
W.WriteLine("?");
W.Flush();
W.Close();
}
public void Search_Contact()
{
string Str, CheckStr1, CheckStr2;
string N; int Pos;
F = new FileStream("Contacts.txt", FileMode.Open, FileAccess.Read);
R = new StreamReader(F);
Console.Write("Enter name: ");
N = Console.ReadLine();
//Code to fetch data and display in proper format
while ((Str = R.ReadLine()) != null)
{
CheckStr1 = "Name: " + N;
Pos = Str.IndexOf("?");
CheckStr2 = Str.Substring(0, Pos);
if ((CheckStr1.CompareTo(CheckStr2)) == 0)
{
while (true)
{
Pos = Str.IndexOf("?");
if (Pos == -1)
break;
Console.WriteLine(Str.Substring(0, Pos));
Str = Str.Substring(Pos + 1);
}
Pos = 0;
}
}
R.Close();
}
static void Main(string[] args)
{
Contact C = new Contact();
int K=0;
int D;
while (K != 2)
{
Console.WriteLine("1. Meeting");
Console.WriteLine("2. Appointment");
D = Convert.ToInt32(Console.ReadLine());
if (D == 1)
{
int M = 0;
Console.Clear();
while (M != 2)
{
Console.WriteLine("1. Add new record");
Console.WriteLine("2. Search new record");
Console.Write("Enter Choice: ");
M = Convert.ToInt32(Console.ReadLine());
switch (M)
{
case 1: Console.Clear();
C.GetContactData();
Console.Clear();
break;
case 2: Console.Clear();
C.Search_Contact();
Console.ReadLine();
Console.Clear();
break;
default: Console.WriteLine("Invalid input");
break;
}
}
}
else
{
int G = 0;
Console.Clear();
while (G != 2)
{
Console.WriteLine("1. Add new record");
Console.WriteLine("2. Search new record");
Console.Write("Enter Choice: ");
G = Convert.ToInt32(Console.ReadLine());
switch (G)
{
case 1: Console.Clear();
C.GetAppointmentData();
Console.Clear();
break;
case 2: Console.Clear();
C.Search_Contact();
Console.ReadLine();
Console.Clear();
break;
default: Console.WriteLine("Invalid input");
break;
}
}
}
}
}
}
}`