|
hi
i'm new
when is it best to use setProperty(val) to set a property and when is it best to use property = val?
thanks
|
|
|
|
|
AFAIK it's pretty much the same (IIRC property's getter and setter are actually ordinary functions, whole property concept is just "syntax sugar" - am I right? ). I think it's matter of style.. would you use person.Age or person.getAge() ? I'd use the first one...
p.s if somebody knows guidelines or something about when to use property and when functions, lemme know!
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
I think its a matter of your personal taste.
I always use properties when its just about setting values. The only situation where I make an explicit setter method is when the setter should have another visiblity than the getter. But this will be obsolete with the next framework version.
|
|
|
|
|
thepersonof wrote:
when is it best to use setProperty(val) to set a property and when is it best to use property = val?
If you don't have any specific logic that needs to be applied to simply set the value of the private variable it is best to use a property. If you need to perform some specific conditional logic, etc. when setting the value typically would use a method.
|
|
|
|
|
Nick Parker wrote:
If you don't have any specific logic that needs to be applied to simply set the value of the private variable it is best to use a property. If you need to perform some specific conditional logic, etc. when setting the value typically would use a method.
This is what ive always stuck to as well, glad im not alone in my thinking on this.
|
|
|
|
|
Hello all
how can i convert an int32 to hexadecimal and string to hexadecimal?
i am working at C#
Thanks alot
|
|
|
|
|
Not too sure what your question means but to display an int in Hex, you can use the ToString() method as below. As for converting a string to Hex, I don't quite understand what you mean.
int convertMe = 102;
string converted = convertMe.ToString("X");
|
|
|
|
|
If you need to convert a string with hexdecimal presentation to int look at the Convert.ToInt32 method.
|
|
|
|
|
|
Hi
maybe i am not making any sense..i am creating a HTML file on runtime and opening it in a Webbrowser control,the html also have links..instead of assigning html or other http file link in SRC tag,i want to call my c# function which grab the particular text from webbrowser control and pass it in some C# function,for instance,my HTML have links
1)Apple 2)Oranges,when i click Apple,then it calls MessageBox with text "Apple" etc..is it possible?how can I inject some code to call c# based routines
Thanks
|
|
|
|
|
I can think of two possible solutions to your problem.
The first is to hook-up an event handler for the browser control's BeforeNavigate2 event. You can then use this to parse special commands passed in the SRC attribute and execute particular methods. An example is shown below.
HTML:
Calls Host Form's MyCommand Method
C#:
private void WebBrowser_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
// Determine if this is a proper url or a command
if (((string)e.uRL).IndexOf("command:") != -1)
{
// Call the appropriate function for the command
switch (((string)e.uRL).Replace("command:", ""))
{
case "mycommand":
this.MyCommand();
break;
}
// Stop the browser from performing the navigation
e.cancel = true;
}
}
The other method is to hook up some event sinks to capture the DHTML events.
Hope this helps.
Aaron
|
|
|
|
|
|
I hope my already 2 day search ends here !
This is what I want to be able to do: existing app A generates sql-qeurys and sends these as strings to app B (application to develop). These querys are send to a database server and the result is put into two different files (one file with result data layout and the other with actual result data).
Now app B must return a struct with information about these files(location etc) and some additional information to app A. App A reads the files and presents the information to the user.
My question now is: how do I send data (using structs with strings, integers etc) between two applications?
My intention is to use Window Messages for this task using SendMessage / WM_COPYDATA. I have not been able to find an example which made it (crystal)clear for me, maybe someone can help me tackle this problem.
Or do you think this approach is not the good one, please tell me!
Thanks in advance,
Darth
I can't get no satisfaction.
|
|
|
|
|
You could just serialize the sturcture and send it as a byte array from app B over a socket to app A and de-serialize it. This way App A and B do not neccessarily need to be on the same computer. Just an idea.
|
|
|
|
|
Sorry, just saw you were using WinCE, disregard my suggestion.....
|
|
|
|
|
Greetings,
I read somewhere that it is better to do a for loop rather than a foreach loop, as they said that it takes extra processing.
Aren't these doing exactly the same thing? It seems to me that the for loop would take more processing.
<code>
For(int i=0;i<myArrayList.Count;i++)
{
((MyClass)myArrayList[i]).myMember = 3;
}
Foreach(MyClass myClass in myArrayList)
{
myClass.myMember = 3;
}
</code>
Any insight would be greatly appreciated.
EB
|
|
|
|
|
foreach makes a call to the IEnumerable interface and gets an IEnumerator
the enumerator is then responsible for itteration through your list.
the little overhead that is involved in the foreach is the actual calls to the enumerator ".Current" and ".MoveNext"
In my oppinion you should use foreach since id take readable code over a very very minor performance increase any day..
unless i really really need the extra cpu cycles that is..
//Roger
|
|
|
|
|
I started using the foreach loops instead of the for loops and found that they are only to be used for read-only operations. (unless I'm missing somthing?) Looks like only the for loop will work if you want to write to the object. I've never used it before but the foreach seems to be working very fast and is nice for the read-only stuff...
Thanks for your reply Roger.
EB
|
|
|
|
|
|
Foreach is definitely slower than For, especially when iterating over typed arrays.
|
|
|
|
|
Robert Rohde wrote:
Foreach is definitely slower than For, especially when iterating over typed arrays.
That will change with generics in .NET 2.0.
|
|
|
|
|
Excellent, I am trying to squeeze every drop of resources that I can without the code being too cumbersome. Thanks for the confirmation on this... looks like I'm just going to stick with the plain-vanilla for-loops on this one.
EB
|
|
|
|
|
|
|
I have a class like the following. The DataClass2 type is also derived from ASuperObject.
public class DataClass1 : ASuperObject<br />
{<br />
private DataClass2 dataClass2;<br />
<br />
public DataClass1(){}<br />
<br />
public DataClass2 MyDataClass2<br />
{<br />
get<br />
{<br />
if(this.dataClass2 == null)<br />
this.dataClass2 = DataClass2Holder.Instance.Dummy;<br />
return this.dataClass2;<br />
}<br />
set{this.dataClass2 = value;}<br />
} <br />
}
From a function I fool around with an instance of DataClass1 and at some time I use the MyDataClass2 property, to get the dataClass2 value.
The dataClass2 has not been instantiated yet, so the 'if' clause sets the value.
Now the function that called the property would like to know, if the 'if' clause was invoked or not (see code below)- can this be done?
int localCount = 1;<br />
PropertyInfo[] properties = this.GetType().GetProperties();<br />
foreach(PropertyInfo property in properties)<br />
{<br />
if(property.PropertyType.BaseType == typeof(ASuperObject))<br />
{<br />
((ASuperObject)property.GetValue(this,null)).nameAddition += localCount+"_"; <br />
((ASuperObject)property.GetValue(this,null)).InitializeHierarchy();<br />
localCount++;<br />
}<br />
}
(it must be general and not just a bool being set in DataClass1)
|
|
|
|