|
Right Scrubb that. I was being thick and thinking the construction was done in the constructor. Which I presume it isn't to make it lazier.
Regards,
Rob Philpott.
|
|
|
|
|
The issue is the static member variable. You should probably declare it private readonly and not static. What you are trying to do with the singleton pattern is force one instance in your application. static classes do that, and if your SomeClass has no internal state, then you should move it to a static class instead. If you insist on keeping the member static, then put the initialization into a static constructor and don't check ==null in the Current property.
public class SomeClass {
private readonly SomeClass _current;
public static SomeClass Current {
get {
if(_current == null) { _current = new SomeClass();}
return _current;
}
}
public SomeClass() {
}
}
public class SomeClass {
private static SomeClass _current;
static SomeClass(){
_current = new SomeClass();
}
public static SomeClass Current {
get {
return _current;
}
}
public SomeClass() {
}
}
Hope that helps.
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Thank you all for helping cause I was going insane trying to figure out why this was happening. It was so very annoying.
By the way Simon thank for the thread safety tip.
|
|
|
|
|
Hi.. i'm making a program and this is how it goes..
I have actually two buttons and having the same event handler... how will i know which button triggered the event?.. what i was planning to do is just to pass a parameter to the method but it seems like the only parameters that is only allowed is the (object sender, EventArgs e)... am not that really proficient in C# so i guess you could give me solutions and workarounds on how to do this
|
|
|
|
|
The object 'sender' is the button that triggered the event.
just cast it to button type and check if it is the one you require.
e.g.
Button b = sender as Button;
if(b == button1)
.....;
else ...;
or you could assign a value in the "Tag" property of the button and check it in the event handler.
regards
|
|
|
|
|
Thanks a lot.. can i also cast like using the java syntax like
"Button b = (Button) sender" <--- is that possible?
|
|
|
|
|
Silvyster wrote: is that possible?
Did you try it? What happened?
|
|
|
|
|
hy everyone!
i would like to start a project in programming a webservice which does some tasks.
but because i have done none before i do not really know where or what to start with. does anyone of you have links, helpful infos or a "best practice" to help me start with? something like a cookbook, which describes how or where to start, if you want to do it the first time?
because i guess it's better to fetch many useful hints instead of just trying things and to get frustrated because it doesn't work as expected
thanks for any useful hint!
stephan.
|
|
|
|
|
Start with small projects and keep with the basics.
Just because we can; does not mean we should.
|
|
|
|
|
Start here: http://support.microsoft.com/kb/308359[^]
It's pretty simple. Create an .asmx page in a webproject, go to the code behind and add a method. Decorate the method with the attribute [WebMethod] and make sure you're only using simple types as parameters. Set you asmx as the start page of your project and hit F5. You should be able to test your method from Internet Explorer.
Regards,
Rob Philpott.
|
|
|
|
|
Hello,
I currently have a form that reads through an xml file and displays information based on the object selected in the combobox.
I can read the information from the xml just fine, but editing and saving the information is where I'm having trouble at.
xml file:
<Objects>
<Object name="Square">
<Height>15</Height>
<Width>15</Width>
<Color>red</Color>
<Object name="Circle">
<Radius>10</Radius>
<Hollow>True</Hollow>
<HollowRadius>5</HollowRadius>
<Color>blue</Color>
</Objects>
How would I change the "Sqaure" objects height value?
or
How would I change the "Circle" objects hollow value to false?
Thanks
|
|
|
|
|
<br />
using System.Xml;<br />
<br />
public void ChangeObjectHeight(string Name, int Height)<br />
{<br />
XmlDocument Doc = new XmlDocument();<br />
Doc.Load("yourfilenamehere.xml");<br />
<br />
XmlNode Node = Doc.SelectSingleNode("/Objects/Object[@name='" + Name + "']");<br />
XmlNode Node2 = Node.SelectSingleNode("Height");<br />
Node2.InnerText = Height;<br />
<br />
Doc.Save("someplacetosavetheshit.xml");<br />
}<br />
or something to that extent.
|
|
|
|
|
Thanks very much, you rock!
|
|
|
|
|
Really? String concatenation? And multiple queries? That's how it's done?
string xpath = string.Format("/Objects/Object[@name='{0}']/Height", Name);<br />
Doc.SelectSingleNode(xpath).InnerText = Height.ToString();
led mike
|
|
|
|
|
Stupefy wrote: that reads through an xml file
How?
Also your XML is not valid so until you fix that it will be difficult to help you.
led mike
|
|
|
|
|
Hello all.
Now that I have discovered extension methods, I am revisiting my libraries of handy-dandy routines to see where it makes sense to convert them. In doing so I am also revisiting a question about how to handle methods that work on different data types.
I am wondering if anyone out there has any opinions or knows any arguments for/against writing such methods in a particular style. I know there probably isn't any one "right" answer, but I thought it would be informative to hear what other programmers think.
For instance, I have a lot of methods that work on strings. I also need the same operations to work on character arrays. So I might end up with something like
public int foo ( char[] SourceData ) { ... }
public int foo ( string SourceData ) { ... }
I have also handled this using
public int foo ( char[] SourceData ) { return foo(new string(SourceData)); }
public int foo ( string SourceData ) { ... }
and even
public int foo ( object SourceData )
{
string source;
if ( SourceData.GetType() == typeof(string) ) source = SourceData;
else if ( SourceData.GetType() == typeof(char[]) ) source = new string(SourceData);
else error_condition;
...
}
I started to look at generics, but it seems that they may be a bit of overkill for routines that only handle 2 or 3 different data types.
Opinions? Critisisms? Other ideas? All are welcome.
Clive Pottinger
Victoria, BC
|
|
|
|
|
cpotting wrote: I started to look at generics, but it seems that they may be a bit of overkill for routines that only handle 2 or 3 different data types.
Why would generics be overkill. Just because you are limiting to only 2 or 3 data types, generics are still very useful. Let's face it, generics (in most cases) are often only used against a couple of types only. Don't limit yourself just because your code doesn't use every possible type.
|
|
|
|
|
Pete O'Hanlon wrote: Don't limit yourself
He may not be.
led mike
|
|
|
|
|
led mike wrote: He may not be.
Smooth. You've definitely mastered the one liner.
|
|
|
|
|
Thanks Pete. I will take a look a closer look at generics.
I'm not quite sure what led mike meant by "He may not be", though.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Well I've had two years of learning from some of the best
led mike
|
|
|
|
|
I'm trying to figure out a way to set a tooltip for each individual ColumnHeader on a ListView. Unfortunately, ListView can't extend ColumnHeader by default, at least that's what ToolTip.CanExtend(object) reports when I try to run it on an instance of ColumnHeader.
I was wondering if anyone could point me in the right direction for this. After doing a Google search I found a few message board postings where WndProc was overloaded on the ListView control butall were too vague or used types they didn't define.
I know column headers in DataGridView are able to handle ToolTips so I'm going to take a look at that via reflector. Hopefully, that'll shed some light on what I need to do.
-JC
|
|
|
|
|
Hi All,
I want to display the sum of the values of a field on my report.
im using 'Running total fields' , then i select the field, bud i don't see the 'Sum' selection on the 'Type of summery' combobox...anyone any idea???
Thanx.
|
|
|
|
|
Try adding a formula field and setting its value to the sum of the field you're looking for.
So the formula text would be something like:
Sum ({Table.Fieldname})
The Sum function also allows you to set specific criteria on what to count. I'm not sure how flexible it is, but it's there.
-JC
|
|
|
|
|
hello allll
i have assingned a task to recognise the image that is a mathematical number 0,1,2,3,4,5,6,7,8,9
using image processing
plz any one guide me through this whole process and regard me code
if anyone have
i have to use c# plz guide me for the C# tooo
waiting for replys
thanks
|
|
|
|