|
farokhian wrote: Can you explain me that what is GUIDs?
Globally Unique Identifier[^]
farokhian wrote: should i create it c# code?
All you will need is to call Managed Call to create GUID
farokhian wrote: How can i use it?
Guid.NewGUID().ToString()
Al thou I Don't recommend this approach for database. The process is very slow, and there you can get duplicates GUIDs.
I Recommend using Integer ID, With Auto_Increment options. When inserting Row, in SQL command do not specify column ID and value. It will grammatically give free ID number
|
|
|
|
|
GUIDs a string values used for uniqueness (example: 33b61dbd-2640-4153-8556-9cb9ad3e4a71). They are great for ensuring a unique identifier but not so great for indexing as they are string and thus cause the DB to have to do a table scan in order sort the records properly. Indentity or auto-increment field types may be old-school but they have the advantage of not needing to scan the table for ordering and thus provide much better performance for indexing. This is important because the Primary Key is an Index, the primary index in fact. The main advantage a GUID provides is with database farms. A record with a GUID will always have the same GUID but the Indentity could get reset across servers if precausons are not taken.
All that being said, I feel your original question was not answered. In order to answer your question though I would need a little bit more info as the answer could differ. How are you connecting to the DB? ADO.Net? Linq? What kind of database are you connecting to? Aceess? SQL? MySQL?
Thank you,
Eric Ritzie
|
|
|
|
|
I want use method in dll using with reflection.
-----------------------------------------------------------
Assembly assembly = Assembly.Load("abc.dll");
object obj = assembly.CreateInstance("Namespace.MyClass");
Type type = assembly.GetType("Namespace.MyClass");
string parameter = "5|2";
object[] param = GetParameters(parameters);
MethodInfo method = type.GetMethod("Sum");
return method.Invoke(obj, param);
-----------------------------------------------------------
Actually this values gets from database in varchar type. Which is string parameter = "5|2".
I use following code in "GetParameters" method for split values;
private static object[] GetParameters(string pParameters)
{
string removeSplitCharacter = pParameters.Replace("|", "");
object[] param = new object[removeSplitCharacter.Length];
int index = 0;
foreach (object item in pParameters.Split('|'))
{
param.SetValue(item, index);
index++;
}
return param;
}
-----------------------------------------------------------
Namespace.MyClass.Sum metod contain following code;
public int Sum(int a, int b)
{
return a + b;
}
I get error; can not convert System.String to System.Int32
If I write "object[] mParam = new object[] { 5, 10 };" instead of parsing parameter value from db program works.
What can I do? Thanks...
|
|
|
|
|
Instead of
param.SetValue(item, index);
use
param.SetValue(Convert.ToInt32(item), index); .
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
Its true but I dont know parameter types. In this example all values are int, "8|5". But may be another parameter like "true|false", or "John|Marry"...
|
|
|
|
|
But then you wont be "adding" true and false (by using the same sum method). Even if you are, you would not add them numerically, right?
It will be a boolean "and" or a string "concatenation".
Are there other overloaded versions of SUM available in the class that you invoke?
If you try to pass a string into a method which uses ints as parameters, you will definitely get the conversion error.
There's nothing left in my right brain and nothing right in my left brain. |
modified on Friday, December 11, 2009 4:40 AM
|
|
|
|
|
I use different dll use for different parameter.
My database table contain varbinary dll and varchar parameter each row.
I want use necessary dll with this dll parameter.
|
|
|
|
|
All I can think of then is that you fetch the parameter from the database and check its type. You then load the assembly you want to use for that type (if it is not already loaded!).
Then go ahead and call the appropriate method.
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
In that case, you have a few problems. The first is that you are assuming that all parameters are the one character long. The second is that your GetParameters method has no way to know what types you need. You need to get the parameter types from your MethodInfo and pass them into the function. Once you have that, you can use the more general Convert.ChangeType to create the right type of object.
Also, for readability's sake, why are you using param.SetValue(item, index) instead of just param(index) = item ?
|
|
|
|
|
Hi all...
when i try to run the SendTcpSynExample.cs i face many errors (nearly 23),
like this
Error 1 The best overloaded method match for 'Tamir.IPLib.Packets.TCPPacket.TCPPacket(int, byte[], Tamir.IPLib.Packets.Util.Timeval)' has some invalid arguments C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 70 29 ConsoleApplication1
Error 2 Argument '3': cannot convert from 'bool' to 'Tamir.IPLib.Packets.Util.Timeval' C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 70 56 ConsoleApplication1
Error 3 Property or indexer 'Tamir.IPLib.Packets.EthernetPacket.SourceHwAddress' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 73 13 ConsoleApplication1
and other errors................
.. Can any one help me to solve them??
Thanks to all...
|
|
|
|
|
Lesson 1: Read and understand!
Error 1 The best overloaded method match for 'Tamir.IPLib.Packets.TCPPacket.TCPPacket(int, byte[], Tamir.IPLib.Packets.Util.Timeval)' has some invalid arguments C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 70 29 ConsoleApplication1
What could this mean? Maybe this "has some invalid arguments" could help!
-> your call to Tamir.IPLib.Packets.TCPPacket.TCPPacket has some invalid arguments.
So I would start there to look for your error!
Next step:
"Tamir.IPLib.Packets.TCPPacket.TCPPacket(int, byte[], Tamir.IPLib.Packets.Util.Timeval)"
-> int, byte[], Tamir.IPLib.Packets.Util.Timeval
This are the parameters the compiler expects. So how to solve?
Just give him what he wants!
Greetings
Covean
|
|
|
|
|
Hi all...
when i try to run the SendTcpSynExample.cs i face many errors (nearly 23),
like this
Error 1 The best overloaded method match for 'Tamir.IPLib.Packets.TCPPacket.TCPPacket(int, byte[], Tamir.IPLib.Packets.Util.Timeval)' has some invalid arguments C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 70 29 ConsoleApplication1
Error 2 Argument '3': cannot convert from 'bool' to 'Tamir.IPLib.Packets.Util.Timeval' C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 70 56 ConsoleApplication1
Error 3 Property or indexer 'Tamir.IPLib.Packets.EthernetPacket.SourceHwAddress' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 73 13 ConsoleApplication1
Error 4 Property or indexer 'Tamir.IPLib.Packets.EthernetPacket.DestinationHwAddress' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 74 13 ConsoleApplication1
Error 5 Property or indexer 'Tamir.IPLib.Packets.EthernetPacket.EthernetProtocol' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 75 13 ConsoleApplication1
Error 6 Property or indexer 'Tamir.IPLib.Packets.IPPacket.DestinationAddress' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 78 13 ConsoleApplication1
Error 7 Property or indexer 'Tamir.IPLib.Packets.IPPacket.SourceAddress' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 79 13 ConsoleApplication1
Error 8 Property or indexer 'Tamir.IPLib.Packets.IPPacket.IPProtocol' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 80 13 ConsoleApplication1
Error 9 Property or indexer 'Tamir.IPLib.Packets.IPPacket.TimeToLive' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 81 13 ConsoleApplication1
Error 10 Property or indexer 'Tamir.IPLib.Packets.IPPacket.Id' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 82 13 ConsoleApplication1
Error 11 Property or indexer 'Tamir.IPLib.Packets.IPPacket.Version' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 83 13 ConsoleApplication1
Error 12 'Tamir.IPLib.Packets.TCPPacket' does not contain a definition for 'IPTotalLength' C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 84 17 ConsoleApplication1
Error 13 Property or indexer 'Tamir.IPLib.Packets.IPPacket.IPHeaderLength' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 85 13 ConsoleApplication1
Error 14 Property or indexer 'Tamir.IPLib.Packets.TCPPacket.SourcePort' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 88 13 ConsoleApplication1
Error 15 Property or indexer 'Tamir.IPLib.Packets.TCPPacket.DestinationPort' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 89 13 ConsoleApplication1
Error 16 Property or indexer 'Tamir.IPLib.Packets.TCPPacket.Syn' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 90 13 ConsoleApplication1
Error 17 Property or indexer 'Tamir.IPLib.Packets.TCPPacket.WindowSize' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 91 13 ConsoleApplication1
Error 18 Property or indexer 'Tamir.IPLib.Packets.TCPPacket.AcknowledgementNumber' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 92 13 ConsoleApplication1
Error 19 Property or indexer 'Tamir.IPLib.Packets.TCPPacket.SequenceNumber' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 93 13 ConsoleApplication1
Error 20 Property or indexer 'Tamir.IPLib.Packets.TCPPacket.TCPHeaderLength' cannot be assigned to -- it is read only C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 94 13 ConsoleApplication1
Error 21 'Tamir.IPLib.Packets.TCPPacket' does not contain a definition for 'ComputeIPChecksum' C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 97 17 ConsoleApplication1
Error 22 'Tamir.IPLib.Packets.TCPPacket' does not contain a definition for 'ComputeTCPChecksum' C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 98 17 ConsoleApplication1
Error 23 The type or namespace name 'GetAllDevices' does not exist in the namespace 'SharpPcap' (are you missing an assembly reference?) C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 129 48 ConsoleApplication1
Error 24 The name 'EthernetFields_Fields' does not exist in the current context C:\Documents and Settings\Free User\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs 43 27 ConsoleApplication1
.. Can any one help me to solve them??
Thanks to all...
|
|
|
|
|
1. What is SendTcpSynExample.cs?
2. Error message are pretty clearly telling what the problem is.
3. To me it looks like a case of incorrect reference. You might be using a different version of dll than what you should.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Hi
I am Newbie in .Net any trying to Generate Ms word Document dynamically on my button click Event i am using the Following code
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";
string strFileName = "GenerateDocument" + ".Doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;fileName=" + strFileName);
StringBuilder strHTMLContext = new StringBuilder();
strHTMLContext.Append("</table>".ToString());
strHTMLContext.Append("<br><br>".ToString()); strHTMLContext.Append(
"<p align='Center'> Note : This is a dynamically generated word document </ p > ".ToString());
HttpContext.Current.Response.Write(strHTMLContext);
string Filepath = System.IO.Path.GetFullPath(strFileName);
frameDoc.Attributes.Add("src", "Filepath");
frameDoc.DataBind();
This Code works Fine and prompts with options Save,Open,Cancel and opens a new Document in Msword
but I want to put this Document in Iframe
Can Anyone help in this Context?
Any help would be appreciated!
|
|
|
|
|
|
Hi, I get this error despite create a delegate..
private delegate void ResumeChart();
ResumeChart ChartResume;
private void ResumeChartLayout()
{
this.m_ChartControl.ResumeChartLayout();
}
void ResetChart()
{
this.Invoke(ChartResume);
}
Inside my constructor I have this.
public frmGraph(String stockQuote,String[] args)
{
InitializeComponent();
newArgs = new String[args.Length];
Array.Copy(args, newArgs, args.Length);
token = newArgs[0];
this.stockQuote = stockQuote;
label1.Text = stockQuote;
this.Text = stockQuote + " Graph";
ChartResume = ResumeChartLayout;
}
Inside my form load, i create a new thread to call another function
private void frmGraph_Load(object sender, EventArgs e)
{
FillDataTable();
m_ChartControl.Charts[0].Data = this.GenareteDataForCandle();
m_ChartControl.SuspendChartLayout();
m_ChartControl.LoadTheme("Manco.Chart.CF.Theme.xml");
m_ChartControl.Charts[0].ChartType = ChartType.Line;
m_ChartControl.Charts[0].ValueAxisList[0].Min = this.m_dStokMin;
m_ChartControl.Charts[0].ValueAxisList[0].Max = this.m_dStokMax;
workerThread2 = new Thread(new ThreadStart(AddAnnotations));
workerThread2.Start();
m_ChartControl.ResumeChartLayout();
}
This is my AddAnnotation function that will invoke the ResetChart() method
public void AddAnnotations()
{
string toa = "calls";
Annotation[] anno = null;
int countA = 0;
int arrayIndex = 0;
while (true)
{
XmlDocument xmlPlogs = getAllPlogs(toa);
XmlNodeList plogs = xmlPlogs.SelectNodes("/PlogList/Plog");
foreach (XmlNode plog in plogs)
{
XmlNodeList receivers = plog.SelectNodes("PlogUnique/Message/Receiver");
foreach (DateTime dt in dateArray)
{
DateTime newDT = Convert.ToDateTime(plog.SelectSingleNode("PlogCommon/TimeOfOccurrence").InnerText);
newDT = Convert.ToDateTime(newDT.ToString("dd MMM"));
String content = plog.SelectSingleNode("PlogUnique/Message/Content").InnerText;
if((content.Contains(stockQuote)) && (newDT.ToString() == dt.ToString()))
{
for (int i = 0; i < dateArray.Length; i++)
{
if (dateArray[i] == newDT)
{
arrayIndex = i;
}
}
anno[countA] = m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();
anno[countA].Location.TypeX = LengthType.Bound;
anno[countA].Location.X = arrayIndex;
anno[countA].Location.TypeY = LengthType.Bound;
anno[countA].Location.Y = 0;
anno[countA].Data = " ";
anno[countA].Font.Size = 4;
anno[countA].Font.Bold = false;
anno[countA].Color = Color.FromArgb(1, 1, 1);
modulePath = this.GetType().Module.FullyQualifiedName;
moduleDir = Path.GetDirectoryName(modulePath);
anno[countA].ImageFile = Path.Combine(moduleDir, "ArrUp.png");
countA++;
}
}
}
Thread.Sleep(5 * 60 * 1000);
ResetChart();
}
}
|
|
|
|
|
Try after changing the ResetChart function like this.
void ResetChart() <br />
{<br />
this.m_ChartControl.Invoke(ChartResume);<br />
}
|
|
|
|
|
hmm.. i still get the same error
could this be the error? under the AddAnnotations method.
anno[countA] = m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();
|
|
|
|
|
Yes. Previously I did not went through the AddAnnotation() function.
Since you ChartControl is in the UI Thread, you can only access/modify the ChartControl properties by using a delegate.
Just like you used a delegate to call the ChartResume method, use another Delegate to add annotation. This will surely solve the problem.
|
|
|
|
|
i have create another Delegate
private delegate void AddAnnotation();
AddAnnotation addNewAnnotation;
private void CreateAnnotation()
{
m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();
}
void cAnnotation()
{
this.Invoke(addNewAnnotation);
}
and under the AddAnnoations method
i change it to
anno[countA] = cAnnotation();
and i get this error
Error 4 Cannot implicitly convert type 'void' to 'Manco.Chart.CF.Layout.Annotation'
i tried change all the void to Annotation but still get error
modified on Friday, December 11, 2009 12:00 PM
|
|
|
|
|
The type ‘T’ must be a non null able value type in order to use it as parameter ‘T’ in the generic type or method system.nullable<T>
How can i solve this Problem?
public class SimpleProperty<T>
{
T _value;
public SimpleProperty(T value)
{
_value = value;
}
public T Value
{
get { return _value; }
set { _value = value; }
}
public string SetValue
{
set
{
_value = ToNumber<T>(value);
}
}
private TP ToNumber<TP>(string input) where TP : struct
{
Type[] paramTypes = new Type[] { typeof(string), typeof(TP).MakeByRefType() };
MethodInfo method = typeof(TP).GetMethod("TryParse", paramTypes);
Object[] parameters = new Object[] { input, null };
if (method != null)
{
if ((bool)method.Invoke(typeof(TP), parameters))
return (TP)parameters[1];
}
return default(TP);
}
}
|
|
|
|
|
I am not clear on your question, but if I understood your need:
Try this:
public sealed class SimpleProperty<t> : IDisposable where T : class, new() // Specify that T must be a class.
|
|
|
|
|
Hi,
Having a class with parent child relationships is quite common (I think), and I normally traverse such trees using recursion.
Class looks like this:
public class Product {
public List<Product> Parents {get; set;}
public List<Product> Children {get; set;}
public string Name {get; set;}
public override string ToString() { return Name; }
}
Recursion will look like this:
public void Dump(Product p) {
Console.WriteLine(p.ToString());
foreach (var child in p.Children)
Dump(child);
}
However, I was told by someone before that using threads will be faster and less expensive.
Can anyone send me a sample code of how to do this? I'm thinking that I should simply change (1) to a ParameterizedThreadStart ... but maybe there's a better practice?
Thanks in advance.
Rafferty
|
|
|
|
|
In fact, the person that told you this does not know the final step of your application or he tried to impress you
You may have multiple threads in order to travers the tree, but in your case, the problem will be the output (Console.Writeline(....)) which is thread safe, you will have a lock in order to block multiple threads to access the output buffer.
So, except if you are sure that you have a multiple core, in order millions of data (but in this case do not use the Console), I advise you to stay thread safe (1 thread and this one will catch the maximum of CPU) or otherwise you wil have a timce slice handling to do and lock/unlock to manage.
You should have a good start with:
Generic Background Worker[^]
Good luck
|
|
|
|
|
can anyone check this code and tell us what is worring with it ?thanks
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static List<Contact> myContact=new List<Contact>();
struct Contact
{
public int ContactID;
public string FirstName;
public string Surname;
public string Email;
}
static void createMenu()
{
Console.Clear();
Console.WriteLine("===============================");
Console.WriteLine("* *");
Console.WriteLine("* Contact Management Solution *");
Console.WriteLine("* *");
Console.WriteLine("* 1. New Contact *");
Console.WriteLine("* 2. Edit Contact *");
Console.WriteLine("* 3. Remove Contact *");
Console.WriteLine("* 4. View All Contacts *");
Console.WriteLine("* X. Exit *");
Console.WriteLine("* *");
Console.WriteLine("===============================");
}
static void Main(string[] args)
{
string strUserSelect;
do
{
createMenu();
strUserSelect = Console.ReadLine();
if (strUserSelect == "1")
{
NewContact();
}
else if (strUserSelect == "2")
{
EditContact();
}
else if (strUserSelect == "3")
{
RemoveContact();
}
else if (strUserSelect == "4")
{
ViewAllContacts();
}
} while (strUserSelect.ToUpper() != "X");
SaveToFile();
}
static void LoadContacts()
{
string strLineIn;
string[] strArrayIn;
Contact ContactIn;
StreamReader Sr = new StreamReader("c:\\Contacts.txt");
while (!Sr.EndOfStream)
{
strLineIn = Sr.ReadLine();
strArrayIn = strLineIn.Split(',');
ContactIn.ContactID = int.Parse(strArrayIn[0]);
ContactIn.FirstName = strArrayIn[1];
ContactIn.Surname = strArrayIn[2];
ContactIn.Email = strArrayIn[3];
myContact.Add(ContactIn);
}
Sr.Close();
}
static void NewContact()
{
try
{
Contact ContactIn;
Console.Write("Contact ID : ");
ContactIn.ContactID = int.Parse(Console.ReadLine());
Console.Write("First Name : ");
ContactIn.FirstName = Console.ReadLine();
Console.Write("Sure Name : ");
ContactIn.Surname = Console.ReadLine();
Console.Write(" Email : ");
ContactIn.Email = Console.ReadLine();
myContact.Add(ContactIn);
Console.WriteLine("Contact has been saved successfully...");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
static void EditContact()
{
try
{
Contact ContactIn;
Console.Write ("Contact ID :");
int ContactID=int.Parse(Console.ReadLine());
ContactIn =myContact.Find(delegate(Contact Con) { return Con.ContactID.Equals(ContactID); });
if (ContactID != 0)
{
myContact.Remove(ContactIn);
Console.Write("First Name : ");
ContactIn.FirstName = Console.ReadLine();
Console.Write("Sure Name : ");
ContactIn.Surname = Console.ReadLine();
Console.Write(" Email : ");
ContactIn.Email = Console.ReadLine();
myContact.Add(ContactIn);
Console.WriteLine("Contact has been updated...");
}
else
{
Console.WriteLine("Contact not found...");
}
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
static void RemoveContact()
{
try
{
Console.Write("Contact ID :");
int ContactID = int.Parse(Console.ReadLine());
myContact.RemoveAll(delegate(Contact Con) { return Con.ContactID.Equals(ContactID); });
Console.WriteLine("Contact has been updated...");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
static void ViewAllContacts()
{
for(int i=0;i<myContact.Count;i++)
Console.WriteLine("{0},{1},{2},{3}", myContact[i].ContactID, myContact[i].FirstName, myContact[i].Surname, myContact[i].Email);
Console.ReadLine();
}
static void SaveToFile()
{
File.Delete("C:\\Contacts.txt");
StreamWriter Sw=new StreamWriter("C:\\Contacts.txt");
myContact.ForEach(delegate(Contact Con)
{ Sw.WriteLine("{0},{1},{2},{3}", Con.ContactID, Con.FirstName, Con.Surname, Con.Email); });
Sw.Flush();
Sw.Close();
}
}
}
Console.WriteLine(" Email :");
ContactIn.Email = Console.ReadLine());
myContact.Add(ContactIn);
Console.WriteLine("Contact has saved successfully...");
Console.ReadLine();
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
static void EditContact()
{
try
{
Contact ContactIn;
Console.Write ("Contact ID :");
int ContactID=int.Parse(Console.ReadLine());
ContactIn =myContact.Find(delegate(Contact Con) { return Con.ContactID.Equals(ContactID); });
if (ContactID != 0)
{
myContact.Remove(ContactIn);
Console.Write("First Name : ");
ContactIn.FirstName = Console.ReadLine();
Console.Write("Sure Name : ");
ContactIn.Surname = Console.ReadLine();
Console.Write(" Email : ");
ContactIn.Email = Console.ReadLine();
myContact.Add(ContactIn);
Console.WriteLine("Contact has been updated...");
}
else
{
Console.WriteLine("Contact not found...");
}
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
static void RemoveContact()
{
try
{
Console.Write("Contact ID :");
int ContactID = int.Parse(Console.ReadLine());
myContact.RemoveAll(delegate(Contact Con) { return Con.ContactID.Equals(ContactID); });
Console.WriteLine("Contact has been updated...");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
static void ViewAllContacts()
{
for(int i=0;i<myContact.Count;i++)
Console.WriteLine("{0},{1},{2},{3}", myContact[i].ContactID, myContact[i].FirstName, myContact[i].Surname, myContact[i].Email);
Console.ReadLine();
}
static void SaveToFile()
{
File.Delete("C:\\Contacts.txt");
StreamWriter Sw=new StreamWriter("C:\\Contacts.txt");
myContact.ForEach(delegate(Contact Con)
{ Sw.WriteLine("{0},{1},{2},{3}", Con.ContactID, Con.FirstName, Con.Surname, Con.Email); });
Sw.Flush();
Sw.Close();
}
}
}
|
|
|
|