Why does my attempt to use a method called "Start_Data_Command_04" in this file produce the stated error ? (I'll list the error immediately after the code)
File Name: Form1.cs
publicpartialclass Form1 : Form
///Lots of other stuff
///////* *************************************************************************** *
* This button Will Start The Data Flood *
* *************************************************************************** */void Button4_Start_Data_Click(object sender, EventArgs e)
The_User_Clicked_A_Button_Called.Start_Data_Command_04(); ////Error Is here
Error 2 An object reference is required for the non-static field, method, or property 'SerialPortPractice_03.The_User_Clicked_A_Button_Called.Start_Data_Command_04()'
The method named "Start_Data_Command_04" is located in this file, and produces an error (no clue if they are related) of its own...
File name: The_User_Clicked_A_Button_Called.cs
(////The Error Is Flagged right here
Error 1 An object reference is required for the non-static field, method, or property 'SerialPortPractice_03.UART.send_command(byte, int, int)'
No matter what word I put in front of the method; e.g., internal, private, public, static, whatever; I still get an error.
The actual method in question is here File Name: UART.cs
publicvoid send_command(byte The_Byte_Array, int Starting_Place, int Length)
This statement is telling the compiler that you have a static method called Start_Data_Command_04 in the class The_User_Clicked_A_Button_Called. Plainly, from the definition of this method, this is not right - this method is actually an instance method. So, you either have to declare an instance of The_User_Clicked_A_Button_Called using new The_User_Clicked_A_Button_Called().userClicked.Start_Data_Command_04(); or you have to add the static modifier to Start_Data_Command_04.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
...then the second error ("Error 1" in my initial example) goes away, but the first one ("Error 2") remains.
My attempts to declare an instance of the method produced more compiler errros.
If you (or anyone who's reading) could tell me the syntax of how to declare an instance of the method in question, I thank you.
More importantly, and an even greater value, would be to show me how to find the syntax for myself.
Performing five or ten different searches on Google and Bing, (and MSDN, which is really Bing, as I understand it) using my best guess of how to phrase it, (e.g., with search phrases like, "C#, The specific syntax for Declaring an instance of a static method in another class" and so on) I did not immediately see an example of the syntax for declaring an instance of a static method in another class.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
This is actually meant as a comment.
It appears that you are using a very non-standard naming convention in your code. This actually makes the code much more difficult for a another developer to read as we all become accustomed to specific casing and naming methodologies. It's all good if this is just something you are writing for yourself, but habits are hard to break and if you work on commercial code with naming schemes like this, you may run into some developers who won't take kindly to it.
You should take a look at Camel Casing[^]. This is the most common way that CSharp developers write code, and if used correctly will be much appreciated by other developers who will have to look at your code sometime. I have taken the liberty of taking one of your methods above to show you what I mean. Cheers.
(////The Error Is Flagged right here
I have an application that store PDF file in a library and do some other stuff like filtering, searching ...
what i want to do is the next:
when the user hit any pdf file in the windows explorer with the left mouse button, I want to add a menu item to that context menu (of the operating system)"Add this book to library for example", so that i can add this file to my app data base without openning the whole application,(using another sub program that took the path of this file).
is there any way to do this please using C#.
This is hard enough in Windows, let alone you venture out to other platforms! Extending the system is not what a typical application does, hence it's not part of the framework. You'd need to write a Shell Extension[^], which has become a bit harder since the introduction of 64-bit machines.
1. Do any of you have tips regarding what I need to remember and what I can simply pull up from Visual Studio?
What's "pull up"? Usually the answer is "when I press '.'", which should be Ctrl-Space. Intellisense shows the available types in the currently loaded namespaces, as available in the currently referenced assemblies. Most members of those types are available, along with any XML-documentation and a reflection of the parameters, and and indication of any overloads.
Maurice Lantier wrote:
2. Do any of you have suggestions regarding the best way to begin remembering code? 3x5 cards, etc...?
Memorizing isn't going to help, you'll need to experiment. A lot.
No, I really mean a lot!
Maurice Lantier wrote:
3. Any suggestions regarding websites to access, good video's, etc... to help with my learning the necessary?
This site, MSDN and Coding4Fun would be my top three; problem is, first is a community, not a school; second is a reference-site, not a manual, third is too complex often to use it for starters.
It couldn't have been the Help-file (available under F1). You obviously have internet, so that's your primary resource - CodeProject and MSDN. The first is the ideal starterplace for new projects, the articles provide a nice basis for new applications, and the forums are usually open. The second is the ideal reference, explaining how the building-blocks that are available, look like.
Best recommendation is a good book, not an ebook, but one you can use to kill small animals. Both Manning and O'Reilly offer a nice range of books.
You're welcome, hope that more people respond with something more original
You should remember the places where you need to look, and where common things are. Intellisense is great when you know what you are looking for, but if you don't know the class name it won't help. For example, a C++ or Java person might try looking for 'Map', and the autocomplete will fail them completely – but knowing that you can find collections under System.Collections.Generic will give you the clues you need.
You also need to develop Google-fu. C# is a very popular mainstream language, and most problems you're likely to have have been solved and published already, if you can find them. StackOverflow is a trustworthy site if it appears with an answer for your question (I'll take the downvotes for recommending it, it's better than CP in my opinion for small, self-contained questions), as is CP, and MSDN.
The best way to learn depends on your personal style. Myself, I enjoy learning by example so I would get a tutorial or a book and leave that on my desk (virtual or real), and then try creating some simple applications to pick things up. The Framework is too big to learn it academically and expect to hold onto it.
A large percentage of my code generally comes from the internet simply because it's both a pain and unnecessary to re-write code that someone else has written and tested. The rest is from writing my own code and adjusting the samples I've found online to fit my purpose. Basically, google-fu
As has previously been said, I strongly advise you experiment. A lot. The best advice I can give you is to code, code and code. It's like learning a musical instrument. You only get better with practice. Make simple projects for yourself and write them. As you get better, you'll find yourself designing better code and reusing functions and classes you've written previously and even get to writing your own code library.
A good book always helps, I feel that "Programming C# 4.0" by Jesse Liberty et al. is an essential desktop purchase. Pretty much the core of the language is clearly explained part by part with a simple example to show you it in use. Jon Skeet's "C# in Depth - Second Edition" will help you better understand what is going on in your programs.
Finally, don't be afraid to experiment and ask for help if you get stuck. We all began somewhere and the majority of people will be keen to help if they can.
iam new to c#. i need to Design a product home and Login forms using c#.How i will add the individual png files i got for this page design. How to add Click events for the button images.
Please guide me or tell some Videos or Links.
Hi lads and lasses, I have just started looking into communication between services and GUI apps. I decided to use Named Pipes but upon reading a lot of documentation and web examples etc etc it seems that after every message is sent and received you have to setup another server/client to get the next message???
Is this the case? What I wanted was a TCP like connection (yes I know that is an option) where I can set a server listening then connect a client and then through the lifetime of the app just pass messages between the two apps (service and GUI).
You're not creating a new listener for each and every message.
You would normally create a listener that waits for connections. Once that connection request arrives, you create a pipe server for that client. That way, you can have multiple clients connected to the service at the same time and no interfere with each other.
Now, if you just want the local machine applications to talk to the server, then the service only has to listen for one connection. It doesn't have to spawn a new server object for each incomming connection.