|
Mark Nischalke wrote: casting the object twice
Whether it casts twice or not, I agree there shouldn't be any need to use both is and as on the same object.
|
|
|
|
|
If it ain't broke don't fix it.
An organization should have coding standards and everyone should follow them. If you have a standard and you find a non-complying file you may fix it (and alert a superior who should endeavor to enlighten the wayward developer). If you have no standard, then don't reformat the code just to "make it more readable".
Any edits you make to the code should otherwise fit the existing format.
LimitedAtonement wrote: I do this kind of thing ALL the time
Then you're wasting time.
LimitedAtonement wrote: ReferenceEquals, not `=='.
For what purpose? == is likely to be overridden to perform what the developer of the class thinks is best, which may simply be ReferenceEquals anyway.
LimitedAtonement wrote: I'm crazy about conserving lines
For what purpose? Other than with compiler directives; you can write C/C++/C# with no line breaks at all. I don't see you doing that; obviously you recognize that whitespace enhances readability (I simply take it to a much higher level ). Back in high school when I was learning BASIC I endeavored to put the most statements on a line as I could -- the result is unreadable by humans. I've matured since then.
LimitedAtonement wrote: some people swear by ALWAYS using braces
I wouldn't say that I swear by it; I recognize that they're not required in some cases. The primary reason is if I need to add an additional statement later, perhaps just during debugging, I don't need to constantly add and remove BRACEs as I work on the code. As an added bonus, by always using them, (I feel) my code has a more cohesive look and feel. Another concern is line length; I've worked in shops where the coding standard specified a maximum line length of eighty characters, BRACEs yield an obvious place to break a line.
<Aside>In my opinion, the BRACEs should be required and the parentheses should not be. Currently, when writing an if statement, you are required to type at least two and at most six delimiters. By requiring the BRACEs rather than the parentheses, the maximim is reduced to four while retaining the minimum of two. Any of you who want to "save keystrokes" should see the logic in this.</Aside>
As to multiple <codelang="text">returns in a method:
They are rarely needed and should only be used when the alternatives are much less readable. In my opinion, single-return methods show that the developer has a more organized concept of program flow and doesn't take shortcuts.
As for the posted code; why not:
Insets insets = obj as Insets;
return ( (insets != null) && (top == insets.top) && (left == insets.left) && (bottom == insets.bottom) && (right == insets.right));
|
|
|
|
|
foreach (Point a in _gr_pts)
{
if (prev != Point.Empty && prev != a)
{
g.DrawLine(_ap_pen, prev, a);
}
prev = a;
}
|
|
|
|
|
I agree with the previous responses: readability is the important bit, and line spacing can seriously improve this - that is one reason why the "how to get an answer" bit at the top of the page stresses to use "code block" or <pre> tags to preserve formating.
Three points:
1) Whatever the company style is, that is the one you use. Making it all look the same is the easiest way to make it all readable - because if the company style makes it all harder to read, then everyone will complain, and the company style will get changed. If everyone codes to a personal style, then everything gets muddled and harder to cope with.
2) My personal preference is always to use braces for a loop of conditional statement. That way, it is much harder to get it wrong when adding a second staement to a single line conditional. This is a lot easier nowadays, with VS etc auto indenting etc., but it is still easier to see what is going on. (It is similar to the reason why C++ accepts "if(A = B)" while C# wont - avoidance of potential problems.)
3) I also indent braces to match the statements in the functional block - I consider them to be a single indented statement in effect. I really hate the open brace at the end of an if statement, with it's matching brace indented. It looks clumsy and makes it difficult yo find matching braces by eye. But, if that is the company style, then I use it. They write the cheques...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hear hear!
OriginalGriff wrote: I consider them to be a single indented statement in effect
They are one statement -- a compound statement. At least that's how it is in C/C++, it seems the C# guys didn't like that concept for some reason.
|
|
|
|
|
I have a need to create an application for a Pocket PC, any variety, not settled on actual device yet.
Is C# the best tool for that and do I need other SDK's or other tools to do this?
Thanks for your advice,
Fred Blair
|
|
|
|
|
If you wish to use the .Net framework you would need to develope using the .Net compact framework [^], which you can get here[^](redistributable)
More information[^] can be found here.
Good luck, and again this framework will only support certain handsets/smartphones that have the Microsoft Mobile OS installed on it.
|
|
|
|
|
Where do you find the info on what software is used for what devices?
|
|
|
|
|
Google helps me out with that. Obviously devices running windows mobile ce have the .net compact framework, most other phones use the Java mobile runtime (unsure of the name) but you can, again, use Google.
|
|
|
|
|
i am very new in socket apps.so i need help regarding a idea. i just develop a simple 2 apps related with socket.
one is server and one is client. they are working fine in a LAN but i want that if my 2 apps is running in two different machine and there is no
lan connection, only internet connection is available then how two apps can interact with each by through socket programming other internet.
suppose there is two machine in two different office and there is no connection between two machine but both the machine can access internet.
in this type of situation how socket client can communicate with socket server which running in different office and internet is available in
2 different office.because we know socket server run on a port and wait for incoming connection and socket client will connect to socket server
through IP of that machine where socket server is running. but my situation we can provide IP address if both are member of same network/LAN but here i
told you that there is no connection between two machine where socket server & client is running. in this case what IP address i need to give to socket client to connect to socket server. i have no idea about this but i search google and found some scratch idea that this type of situation can be handle
through WAN IP. so please tell me is it right concept or not. if right then how socket client will know that what is the wan IP of that machine where socket server is running or suppose if i know the wan IP of that machine where socket server is running then can my socket client can communicate with
socket server just by WAN IP.
so please someone give me the idea in detail as a result i can handle this situation and also will be able that to program in such way that socket client
can communicate with socket server if there is no LAN connection but internet connection is available.
please help me with idea and if possible give me a sample code
tbhattacharjee
|
|
|
|
|
If your server has an static IP, then connect to that IP.
If your server has an dynamic IP, then use dynamic dns to connect to that dynamic dns name.
If the server behind a router and has only a local IP, like 192.168....
then you must set the port forwarding in router, to forward all request
from specific port to your server.
If you do that, then it is easy to connect, just for example :
Server : myserver.mydomain.com Port 123
You client can connect to myserver.mydomain.com Port 123, and it works just like in a LAN.
|
|
|
|
|
hi guys
i have table in sqlserver database named tels has columns tels_no , tels_name , tels_cost
ok
i want to enter a no in a textbox in the application then auto it get data of this no and set this in two different textboxes one for tels_name and other for tels_cost
how??????????
i do not know
thanks,
Mohamed El-Wehishy
|
|
|
|
|
You can use ADO.net or data set to get you data from DB.
|
|
|
|
|
Yeah, great answer. I'd mark it as "bestest ever" but the developers of this site probably
never knew you'd come along...
Blikkies wrote: You can use ADO.net or data set to get you data from DB.
What the hell does that bring to anything?
It's like somebody asked: "I'm having trouble fitting windows in my house, I know where I want them and I have a fitting kit for them" and you answered "You can use a hammer or its handle to bang nails into a wall."
As for the author of the question, you'd be better off reading a book on C# and/or a tutorial online.
Rome was not built in a day.
var question = (_2b || !(_2b));
|
|
|
|
|
Greg Chelstowski wrote: What the hell does that bring to anything?
at least i gave him something to google.
|
|
|
|
|
yesssssss
man you are right
sorry for this silly question
Mohamed El-Wehishy
|
|
|
|
|
SqlConnection conn = new SqlConnection(@"user id=sa; Password=pass; initial catalog=databaseName; Data source=localhost");
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Tabel WHERE tels_no = '"+textbox1.Text.Replace("'","")+"'";
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
TextBox2.Text = reader["tels_name"].ToString();
}
Use following namespaces:
using System.Data;
using System.Data.SqlClient;
|
|
|
|
|
|
This is an example code, not code that im using. instead of Preaching to me, Give this guy a solution or back off.
|
|
|
|
|
Secondly i USED REPLACE IN THE QUERY
|
|
|
|
|
1 - your code does NOT stop injection attacks
2 - if you give people here code, they are likely to use it verbatim, not ever understand it
3 - why give people examples they shouldn't use ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Please, please, purrrrleeees stop using "I need help" for every topic line. Use something like "Problem retrieving data", or similar.
Errm...., obviously not if it's a Graphics question but you know what I mean.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I setup a wpf project in TFS and checked it in. Now, when I try to open the project I get the following error.
"The project 'projectname' is under source control. This version of Visual Studio .NET does not support source controlled projects. Any changes that you make to this project will not be propagated to source control."
Everyone else on my team can access the project without any difficulties. This tells me that there is something on my machine that it just doesn't like. However, I have no issues when I open other projects from TFS. Has anyone else had this issue? If so, how do you fix it. I have uninstalled and re-installed Team Explorer and Visual Studio but this did not correct it.
|
|
|
|
|
Have you enabled Team Foundation pluging in Visual Studio? Just installing Team Foundation Client is not enough.
Select the plugin in Visual Studio options, under Source Control: here is a screenshot.
|
|
|
|
|
It is set to TFS. All of my other projects pull back fine. However, the WPF application will throw that error. I've seen questions about this happening with web development version but I can't find anything for WPF projects. When the project does load it takes the files out of source control.
|
|
|
|