473,804 Members | 3,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ResponseXmlPars er
{
public static Hashtable GetProductInfoL ist()
{
XmlTextReader xmlTextReader;
bool isScheduleEleme nt = false;
bool isResultItem = false;
ProductInfo productInfo= new ProductInfo();
Hashtable productInfoList = new Hashtable();
try
{
//Create an instance of the XMLTextReader.
//MaterialSearchR esponse.xml is different for different users.
xmlTextReader = new XmlTextReader(" MaterialSearchR esponse.xml");
// Process the XML file.
while (xmlTextReader. Read())
{
if(productInfo == null)
productInfo = new ProductInfo();
if (xmlTextReader. NodeType == XmlNodeType.Ele ment)
{
if (xmlTextReader. Name == "CHECK_SCHEDULE _EX")
isScheduleEleme nt = true;
if (xmlTextReader. Name.Equals("CH ECK_ITEM_OUT"))
isResultItem = true;

if (!isScheduleEle ment && isResultItem)
{
switch (xmlTextReader. Name)
{
case "ITM_NUMBER ":
if (!xmlTextReader .IsEmptyElement )
productInfo.Ite mNumber =
xmlTextReader.R eadElementConte ntAsInt();
break;
...
...
..
case "REQ_QTY":
if (!xmlTextReader .IsEmptyElement )
productInfo.Req uestedQuantity =
xmlTextReader.R eadElementConte ntAsInt();
if (productInfo != null)
productInfoList .Add(productInf o.IPC, productInfo);
productInfo = null;
break;
}
}
}
}//END OF WHILE
}
catch (XmlException ex){}
catch (Exception ex){}
finally
{
if (xmlTextReader! = null)
xmlTextReader.C lose();
}
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 1653
>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
1484
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 what I am missing Bil static void Main(string args SqlConnection connection try // to open the connection to the database connection=new SqlConnection((string)( System.Configuration.ConfigurationSettings.AppSettings))
15
2100
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 reference to some of the ClassA objects created in ClassB. In ClassC I hook into the ClassA events with a foreach loop so that I hook each object. The code is something like this: class ClassC { void SomeMethod() { foreach (ClassA item in...
4
1439
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 confused. 1.) Whenever you declare a class - MyClass - is the class alive in memory for the whole duration of the program? If so, then, since it was not created via the "new" keyword (like an instance is), is it on the heap or stack?
4
2663
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: To keep it really easy let's say this is the code: function addition(int, int); int X;
2
1234
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 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:
1
5043
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 generic class, MyStatisticsClass, with a type parameter T where T is a numeric object type (e.g., Integer, Double, or any class that extends java.lang.Number). Add a method named standardDeviation that takes an ArrayList of type T and returns as a...
5
1692
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 reality????? have a look at my code .....
12
3033
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 as follows. /** Prototype Class **/ public class Cookie implements Cloneable { public Object clone() {
8
1313
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 `CPolygon::area()' The code is listed below:
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.