Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello,
 
I have question class emp
eid,ename,salary,desig i want to insert dyanmicaly through user interface into
listclass
List<emp> li=new List<emp>();
List(emp) li =new List(emp)();

i have separated method for inserting and deleting can u guide me any send snippets
in web application
Posted 3-Jan-13 21:30pm
Edited 3-Jan-13 21:35pm
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You may create the list instance and then pass it to the 'insert' and 'delete' methods. e.g.
 
public static void my_insert(List <string > li)
   {
     li.Add("foo");
     li.Add("boo");
     li.Add("goo");
   }
   public static void my_delete(List<string> li)
   {// deletes all but the very first element
     if (li.Count > 0)
     {
       string s = li[0];
       li.Clear();
       li.Add(s);
     }
   }
 
   public static void Main()
   {
     List<string> li = new List<string>();
     my_insert(li);
     my_delete(li);
     foreach (string s in li)
     {
       Console.WriteLine(s);
     }
   }
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 4-Jan-13 4:07am
   
My 5, but -- one addition. OP's code would not compile, so I added a small answer. And the names "my_insert" and " my_delete" violate Microsoft naming conventions. You may disagree with them, but I think they are good, should be followed. —SA
CPallini at 4-Jan-13 4:13am
   
Thank you. I didn't see the OP code (possibly the edit was in progress), thank you for addition. I suppose the 'POSIX name convention' is in tune with my current mood :-).
Sergey Alexandrovich Kryukov at 4-Jan-13 4:23am
   
I don't dare to insist. Suit yourself. :-) But the readers have the right to know. :-) —SA
CPallini at 4-Jan-13 4:48am
   
"But the readers have the right to know" Definitely. :-D
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is not a valid C# code. The second line won't compile, and it does not make any sense. If you knew that, you should have mentioned that.
 
—SA
  Permalink  
Comments
CPallini at 4-Jan-13 5:13am
   
5.
Sergey Alexandrovich Kryukov at 4-Jan-13 7:14am
   
Thank you, Carlo. —SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 515
1 OriginalGriff 498
2 Abhinav S 305
3 sanket saxena 295
4 thatraja 235
0 Sergey Alexandrovich Kryukov 8,482
1 OriginalGriff 4,830
2 Peter Leow 3,794
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid