Original Post
Please go through the program below.... In this prog i tried to extract data from a text file and then copy it into subscriber instances problem with this code is once the webmethod is called in Main, the control is not goin to the called method, its directly showing the output as null!!! help me..to...understand this problem class Class1 { public static void Main(string[] args) { subscriber[] subscr; subscr = new subscriber[4]; for(int i=0;i<4;i++) { subscr = new subscriber(); } solution sol; sol = new solution(); subscr = sol.webmethod(@"D:\Documents and Settings\parimi.nandini.devi\Desktop\nandu\TestData.txt"); for(int i=0;i<4;i++) { Console.WriteLine(subscr.name); Console.WriteLine(subscr.number); Console.WriteLine(subscr.street); Console.WriteLine(subscr.city); Console.WriteLine(subscr.zipcode); } } } public class subscriber { public string name; public int number; public string street; public string city; public int zipcode; } class solution { public subscriber[] webmethod(string filepath) { subscriber[] sub; sub = new subscriber[4]; if (filepath.EndsWith(".txt")) { StreamReader sr = new StreamReader(filepath); string str = sr.ReadLine(); for (int i = 0; i < 4; i++) { sub = new subscriber(); while (str != null) { int y = str.Length; int s = str.IndexOf(" "); sub.name = str.Remove(s,(y-s-1)); int s1 = str.IndexOf(" ", s + 1); string temp = str.Remove(s1,(y-s1-1)); sub.number = Int32.Parse(temp.Substring(s + 1)); int s2 = str.IndexOf(" ", s1 + 1); string temp1 = str.Remove(s2,(y-s2-1)); sub.street = temp1.Substring(s1 + 1); int s3 = str.IndexOf(" ", s2 + 1); string temp2 = str.Remove(s3,(y-s3-1)); sub.city= temp2.Substring(s2 + 1); int s4 = str.IndexOf(" ", s3 + 1); string h = str.Substring(s3+1); sub.zipcode= Int32.Parse(h); } str = sr.ReadLine(); } return sub; } else { Console.WriteLine("input is not in a correct format"); return sub; } } }