473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Confusion over Static class and Static method!

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
2 1637
>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
Thanks Mattias, it helped :)

Feb 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Bill | last post by:
When I compile the following code fragment, the compiler errors saying the variable connection is not initialized. As I understand C#, I thought it would be initialized. Please help me and explain...
15
by: Rhy Mednick | last post by:
I have a class (let's call it ClassA) that I've written which has events. In another class (let's call it ClassB) I create a collection of ClassA objects. In a third class (ClassC) I create a...
4
by: Jesika | last post by:
I'm coming from a 3 year C background with some basic knowlegde on the Win32 API. I just started learning C# a day ago and I have a couple questions that I need cleared up that just have me very...
4
by: Ranginald | last post by:
Sorry for the simple question but thanks in advance: My goal is to create reusale code for a web app in C#. I have written the code already as a windows app but here is where I am confused: ...
2
by: Anup Daware | last post by:
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...
1
by: bjwillykajilly | last post by:
Well, I got an assignment due this morning, so i guess ill end up turning it in a day late eh. anyways. I have a couple problems that I don't know what to do with. the objective is here: Write a...
5
dmjpro
by: dmjpro | last post by:
i know that the finalize method is called by JVM when an object is garbage collected. right??? but the ultimate memory release done by native OS. now my confusion is ... when it is called in...
12
sumittyagi
by: sumittyagi | last post by:
Hi everybody! I am having a difficulty in understanding the prototype pattern. Actually I got the idea behind it, but the example given in wikipedia for this pattern have confused me. The code is...
8
by: tharringtonan | last post by:
I am compiling the following code, main.cpp, as follows: gcc main.cpp I get the following compile error: main.cpp: In function `int main()': main.cpp:28: no matching function for call to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.