By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

Confusion over Static class and Static method!

P: n/a
Hi Group,
I have a little confusion over the use of static class in C#.

I have a static method in my static class. This method reads an xml
and returns a collection of objects.
This collection of objects can be different for different users.
This method uses some non-static variables which are local to this
method.

Following is my static class:
public static class ResponseXmlParser
{
public static Hashtable GetProductInfoList()
{
XmlTextReader xmlTextReader;
bool isScheduleElement = false;
bool isResultItem = false;
ProductInfo productInfo= new ProductInfo();
Hashtable productInfoList = new Hashtable();
try
{
//Create an instance of the XMLTextReader.
//MaterialSearchResponse.xml is different for different users.
xmlTextReader = new XmlTextReader("MaterialSearchResponse.xml");
// Process the XML file.
while (xmlTextReader.Read())
{
if(productInfo == null)
productInfo = new ProductInfo();
if (xmlTextReader.NodeType == XmlNodeType.Element)
{
if (xmlTextReader.Name == "CHECK_SCHEDULE_EX")
isScheduleElement = true;
if (xmlTextReader.Name.Equals("CHECK_ITEM_OUT"))
isResultItem = true;

if (!isScheduleElement && isResultItem)
{
switch (xmlTextReader.Name)
{
case "ITM_NUMBER":
if (!xmlTextReader.IsEmptyElement)
productInfo.ItemNumber =
xmlTextReader.ReadElementContentAsInt();
break;
...
...
..
case "REQ_QTY":
if (!xmlTextReader.IsEmptyElement)
productInfo.RequestedQuantity =
xmlTextReader.ReadElementContentAsInt();
if (productInfo != null)
productInfoList.Add(productInfo.IPC, productInfo);
productInfo = null;
break;
}
}
}
}//END OF WHILE
}
catch (XmlException ex){}
catch (Exception ex){}
finally
{
if (xmlTextReader!= null)
xmlTextReader.Close();
}
return productInfoList;
}
}

My doubts are:
1. Does a non-static local variable of static methods works fine in
multi-user environment (Web Application) where method is expected to
return different results?
2. Is there any other performance a benefit using the static methods
except the non-requirement of creation of object of class in which
method resides?

Thanks,
Anup Daware

Feb 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
>1. Does a non-static local variable of static methods works fine in
multi-user environment (Web Application) where method is expected to
return different results?
Yes.

>2. Is there any other performance a benefit using the static methods
except the non-requirement of creation of object of class in which
method resides?
When chosing between static and instance member, performance should
generally not be the deciding factor. Focus on good design.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 2 '07 #2

P: n/a
Thanks Mattias, it helped :)

Feb 5 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.