|
I almost never use this , unless it is the constructor case you mentioned.
|
|
|
|
|
In most cases, I've just seen people use the "this" keyword to trigger intellisense.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I've seen people use it for intellisense (however, CTRL+J will bring up intellisense without having to type 'this').
Some tools, such as widely-used Resharper tool issues warnings for using 'this' when it's not needed. Since it purely is excess typing and more words to read while reading code, I recommend against using 'this' keyword unless it's warranted (e.g. the constructor example or passing the current class instance into a function).
|
|
|
|
|
Hello,
Poolee wrote: this.sayHelloWorld = sayHelloWorld;
I wouldn't want to see a codeline like this in my project!
There for, I only need "this" when passing an instance to a function. (like Judah pointed out very well)
All the best,
Martin
|
|
|
|
|
Thanks for your reply.
So just to clarify, you would use a differently-named private variable to the passed variable name?
Cheers
Poolee
... pessimists are rarely disappointed ...
|
|
|
|
|
Poolee wrote: So just to clarify, you would use a differently-named private variable to the passed variable name?
Yes!!!!
All the best,
Martin
|
|
|
|
|
I think it is a matter of style. I don't have anything against using this when it is superflous and I won't go around changing anyone's code that uses it.
My personal style is to not use this unless it is needed or unless it helps code readability.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
You specify this to tell the compiler or yourself it's about this class, not somewhere else.
I almost only use it in the constructor example you mentioned, and very occasionally when eg I do something with a form like this.Close(); or if(this.DialogResult == DialogResult.OK)...
One of my colleagues uses this to point out variables that are defined globally in the class. Please, for the sake of your dear fellow colleagues, avoid this ..... in this case !
V.
No hurries, no worries
|
|
|
|
|
V. wrote: One of my colleagues uses this to point out variables that are defined globally in the class. Please, for the sake of your dear fellow colleagues, avoid this ..... in this case
I find it more readable when this is used like this :P
It's all down to style and personal preference.
|
|
|
|
|
yeah man f*ck this
|
|
|
|
|
Indexers have to be declared with 'this'.
public string this[string theThingIWant ]
{
get
{
return _myListOfStuff[theThingIWant];
}
set
{
myListOfStuff[theThingIWant] = value;
}
}
-- modified at 3:13 Friday 3rd August, 2007
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
This is a fun one!!!
I have a ActiveX control that automatically creates files at certain intervals and save them to a folder on the hard disk. I have no control over the file name the ActiveX control uses and cannot see a way to capture the file name as it is being stored to disk.
I do however know the path, it is a set path that I do have control over.
So how would the code look to into the folder (let's say c:\data) find the file that was written last (the most recent file in the folder) and put the whole path (c:\data\1234556.txt) into a textbox? It has got to be easy but I am not getting it. I want it so when I click a button, I can see that last log file path that was put into the directory.
I got close when I used the ".LastWriteTime" property, and using a messagebox I was able to get it to show me the date and time of the newest file correctly but I don't know how to get the filename of that particular file.
Here is what I have so far, and I think I am close.
String ImgPath = textBox2.Text;
FileInfo myFile1 = new FileInfo(ImgPath);
String NewFile = myFile1.LastWriteTime.ToString();
MessageBox.Show(NewFile);
Thanks in advance!!!
Mike
|
|
|
|
|
newb2vb wrote: but I don't know how to get the filename of that particular file.
Keep using the intellesense until you find it because I don't think there is any DOCUMENTATION FOR FileInfo
|
|
|
|
|
Yes, it's really a shame that they forgot to implement this in their DOCUMENTATION[^]
All the best,
Martin
|
|
|
|
|
Yeah telling people that documentation "does" exist doesn't seem to be working so I thought I would try some reverse psychology and well.... see it worked but on the wrong person.
|
|
|
|
|
led mike wrote: so I thought I would try some reverse psychology
Yes, I'm also using this very often with my kids!
led mike wrote: see it worked but on the wrong person
All the best,
Martin
|
|
|
|
|
Hi..
this is the first time I ask a question in this forum .. I'm a beginner
in C#
my question is: is there a way to make a button circular?
thanks
|
|
|
|
|
|
The poster above has given two very good articles, however, if you want to get very fancy then you really ought to look at the Windows Presentation Foundation within .NET 3.0/3.5 Frameworks.
WPF makes GUI development alot more easy and at the sametime adding more flexibility then what was provided in the previous versions of the .NET Frameworks.
|
|
|
|
|
I need to set up an array would look something like this but I'm not sure what type
basicly i have a list of occrences lets say bob rob bob joe bob joe joe rob jay jay jay rob jay jay jay rob rob joe jay jay jay
and from that I would have to "sub total" the list into something like this
name count
bob 3
rob 5
joe 4
jay 9
1) what type of array would this be
2) how would i prevent it from adding duplicate names?
|
|
|
|
|
Any type of array would work and "you" could prevent it from adding duplicates by checking for the existence of it right? There are many different ways to do this, I would imagine you can find one of them yes? What course is this for?
|
|
|
|
|
its not for a class its for something at work
we have a db of incidents or tickets
and each ticket has a type for example: Microsoft word or outlook or account lockout
I make reports for my boss each month on how many of each we had but I am currently using excel for this which sucks
so I'm trying to automate it ( or at least make an app he can run himself)
I currently have it so that i can download it into a datagridview and filter it using bindingsource.filter but to graph it for him i would like to get totals and i also need to consolidate the names so that i can auto populate some of the combo boxes
I just didnt know if there was a better way to "link" the cells in the array so that if I found bob I could +1 the bob total with out it getting misaligned
|
|
|
|
|
crash893 wrote: we have a db of incidents or tickets
SQL can do subtotals
crash893 wrote: its for something at work
What do you do at work? Just curious.
|
|
|
|
|
I thought about using the count feature in a query but the data is filtered at the binding source by the user and it would be "to hard" to run sql querys allot on the server that has this info. so i basically take one huge dataset add it to a binding source then filter it from there (what ever the user wants to see)
then the idea is that they hit a button and it produces an array that goes into a graphing class and out pops a beautiful bar graph.
usatoday
I'm in IT but I'm not a programmer I'm just doing this for the fun / self education.
I have so far something like (this is quasi sudo code)
foreach (DataRowView view in myBindingSource)
{
If ( array.find((string)view["cat_name"] != 1)
{
array.add((string)view["cat_name"] ,1)
// the ,1 is the total feild so im having some trouble with that
}
else "find index of catname and add +1 to the total"
}
return array
|
|
|
|
|