|
In my web application , we are using Asp.net and C# , Some more method are give warning .
The warning it CA1822 Mark members as static
Its recomended to change static method.
But what i feel, if we are using static in more methods , its will go apart from the object
so memory its maintain all time even any request not comes. and if may access N number of user , Entire user request is try to using these same block of code( memory ). So may be happened performence issue . Or need to synchronize this code.
Please help me whats is happening exactly...
Thanks
|
|
|
|
|
anishkannan wrote: Please help me whats is happening exactly
All this means is that the method isn't accessing any instance members of the class (non-static fields/properties/methods). If you aren't accessing instance members and you are, say, passing in variables to your method the variables *might* be better expressed as fields or properties, improving the class design.
anishkannan wrote: But what i feel, if we are using static in more methods , its will go apart from the object
so memory its maintain all time even any request not comes. and if may access N number of user , Entire user request is try to using these same block of code( memory ). So may be happened performence issue . Or need to synchronize this code.
Marking the method can (not does) result in a measurable performance gain (see http://msdn.microsoft.com/en-us/library/ms245046.aspx[^]). It doesn't make it any less part of the class, it just decouples it from instances. If you think making the methods static will worsen performance or the static methods aren't semantically correct for your object, then you can suppress the warning perfectly safely:
#pragma warning disable 1822
public void Foo()
{
}
for individual warnings or add /nowarn:1822 to the compiler options. Personally I'd go for the individual warning unless it becomes a huge hassle.
|
|
|
|
|
Thanks for reply...
Warning disable is ok . Sorry, if any thing ask wrong...
Apart from that, Incase we use static function in page class. All private methods are static. if accessing 1,00,000 users at same time on the page. so all the user request are try to execute that same memory ( because of static method ). In this scenario which one is the best way avoid the static or can use
Thanks
|
|
|
|
|
Can use: each user gets a separate memory space and thus a separate static variable.
You cannot share information between users via a static variable or method!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
To add to Keiths answer, use
#pragma warning restore 1822 after the last method you want to stop the compiler complaining about.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
|
Hi, I have large XML, with many records. I would like to use SAX parser to read the xml and load it into datagridview and vice-versa. Please let me know whether it is possible. If yes, pls guide me. Thanks in advance.
|
|
|
|
|
|
|
In my pc there are few applications which sends request to server and receives response.
I want to make an application which will block few requests sent by those applications.
How can I do this ?
|
|
|
|
|
I'm chosing to assume you aren't doing this for malicious purposes. Please don't.
A decent firewall will allow you to stop a program from accessing the internet.
|
|
|
|
|
I want to make such firewall or want to hook into some process to do that.
I have downloaded NetDefender and Easy Firewall and few others. But after adding rules, none of them was able to block.
I also tried "Block All" option of NetDefender application. But it could not block.
Every time I receive a message something like "Could not register rule with network adapter". I am the administrator so there should not be any problem with permissions but I don't know why it is not working.
|
|
|
|
|
|
From the first string I need to build the second string, I know it can be done reiteratively but I'm wondering if there is a cute method of achieving this.
From this
"/100/101/201/"
I need to create this string - note the pipe delimiter.
"/100/|/100/101/|/100/101/201/"
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Define Cute?
You could split it, convert to integers, apply some lickety-split maths, reconvert to a string and concatenate.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Dunno if it's cute but I'd do a string.split and double-loop over the resulting array.
If the "records" are always fixed to 3 digits long you can do something like:
public string Foo(string original)
{
string output = original;
string remainder = outputstring.RemoveLastFourCharacters();
while (remainder.Length > 0)
{
output = remainder + "|" + output;
remainder = remainder.RemoveLastFourCharacters();
}
return output;
}
Obviously RemoveLastFourCharacters doesn't exist, I'd add a RemoveEndCharacters(int numberOfCharacters) type method or extension method. The other thing to consider is a StringBuilder , but only if the original string is likely to be long.
|
|
|
|
|
My mistake - # characters, it is basically a heirarchy id as a string. JAAN got the cutest result.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Bah! I did not haz TeH Codez!
|
|
|
|
|
I wouldn't call it cute, but it is clear:
string source = "/100/101/201/";
string resultWanted = "/100/|/100/101/|/100/101/201/";
string[] items = source.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
StringBuilder item = new StringBuilder("/");
StringBuilder sb = new StringBuilder();
string separator = "";
foreach (string s in items)
{
item.Append(s);
item.Append("/");
sb.Append(separator + item);
separator = "|";
}
if (sb.ToString() == resultWanted)
{
MessageBox.Show("OK");
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
That was the method I basically was going to use, JAANs one is decidedly cute and I may even learn something from it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: I may even learn something from it.
Like "Don't use Linq operator except to make yourself indispensable"?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
string actual = "/100/101/201/";
var result = actual.ToCharArray()
.Select((x, y) => new { ch = x, pos = y })
.Where(x => x.ch == '/' && x.pos > 0)
.Select(x => actual.Substring(0, x.pos + 1))
.ToArray();
string derived = String.Join("|", result);
Console.WriteLine(derived);
Is this cute?
"Never put off until run time what you can do at compile time."
- David Gries, in "Compiler Construction for Digital Computers", circa 1969.
|
|
|
|
|
And the winner is - thats about as cute as they get and yest obfuscated it certainly is.
Thakn you for the codez
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: the winner
"Never put off until run time what you can do at compile time."
- David Gries, in "Compiler Construction for Digital Computers", circa 1969.
|
|
|
|
|
Cute? Yep!
Works? Yep!
Easily understood? Nope!
Gets a 5 from me anyway
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|