Click here to Skip to main content
15,891,864 members
Everything / Programming Languages / C# 3.0

C# 3.0

C#3.0

Great Reads

by Jeffrey Walton
Import and export Cryptographic Keys in PKCS#8 and X.509 formats, using Crypto++, C#, and Java.
by Daniel Vaughan
Calcium provides much of what one needs to rapidly build a multifaceted and sophisticated modular application. Includes a host of modules and services, and an infrastructure that is ready to use in your next application.
by Dark Daskin
Article describes how to build an assembly that exposes functions to unmanaged code without C++/CLI
by Sacha Barber
It would probably be like Cinch, an MVVM framework for WPF.

Latest Articles

by Shivprasad koirala
Design Pattern FAQ - Interview Questions (Quick Reference)
by Harsha T, Amarnath S, S Mahesh Reddy
A simple viewer of images stored in the DICOM 3.0 File Format (C#). The file should have raw pixel data, uncompressed. Window Level functionality is also provided.
by AlexeyYakovlev
This paper demonstrates a technique of building Sprache parsers using grammar inheritance.
by Randy Kroeger
This article provides an example on how you can change application configuration settings within an existing ClickOnce publish, update the manifest files, followed by using the Mage utility for updating the manifest using the existing cert file.

All Articles

Sort by Updated

C# 3.0 

17 May 2008 by #realJSOP
One method for loading common and object-specific data from your app.config file.
28 Sep 2008 by #realJSOP
Put text on a bitmap, make your winform app go full-screen, and say hello to some simple LINQ code.
1 Oct 2008 by #realJSOP
Implement repetitive tasks at consistent intervals
2 Oct 2008 by #realJSOP
Discusses windows authentication and application-specific authentication for WinForm applications
11 Dec 2010 by #realJSOP
Scrape the My Articles page here on CodeProject to keep an eye on your articles.
17 Dec 2008 by #realJSOP
A not-so-dotNet way to allow multiple programs to share a single settings file
4 Jan 2009 by #realJSOP
A utility that you can use to "exercise" your inkjet printer without wasting a lot of ink or paper
11 Jan 2010 by #realJSOP
Use Spy++ to get a handle to the start button, and then post the appropriate system message using that hwnd.
13 Jan 2010 by #realJSOP
Put pointy brackets around it and parse it like XML with Linq-to-XML. Just treat everything like an Attribute.// our original stringstring text = "screen_fadetimeout=\"0\" font=\"Courier New\" fontsize=\"11\" linesize=\"4\" theme_color1=\"-1518056\" theme_color2=\"-9674238\"";// add our...
14 Jan 2010 by #realJSOP
Why won't this work?int divisor = 983;int dividend = 1;int scale = 2000;string padding = "";padding = string.Format("{0}{1}{2}", "{0:0.", padding.PadRight(scale, '0'), "}");string result = string.Format(padding, (double)dividend / (double)divisor);Of course,...
14 Jan 2010 by #realJSOP
I would have used a StringBuilder instead of a LinkedList, and decimal instead of int...decimal Rem = 10;decimal Number = 983;int MAXLEN = 2000;StringBuilder result = new StringBuilder("0.");for (int i = 0; i
14 Jan 2010 by #realJSOP
Here's a better answer:This is your version. It takes 2000 calculations and string moves, and generates incorrect results to boot:static string Method1(){ int iterations = 0; decimal Rem = 10; decimal Number = 983; int MAXLEN = 2000; StringBuilder result = new...
14 Jan 2010 by #realJSOP
Look at the text your tried to copy, and you'll see the appropriate characters.When you copy the code from the screen, it's substituting the escape codes for the characters.
14 Jan 2010 by #realJSOP
Run it through the debugger and find out.
15 Jan 2010 by #realJSOP
You can't improve "average" developers via documents discussing proper object-oriented techniques. It's kind of like the old phrase, "You can lead a horse to water, but you can't make it drink."Second, if you can't describe ALL of the necessary OO terminologies in 30 pages, your article is...
20 Jan 2010 by #realJSOP
Beyond what others have said, you really shouldn't throw a message box at the user when they type an invalid character. Just beep the speaker, and be done with it.
26 Jan 2010 by #realJSOP
My most often used design pattern is the SWC pattern (Start Writing Code). It has served me well for almost 30 years.
30 Jan 2010 by #realJSOP
Right off the bat, I've noticed that you spelled the name of the method wrong. It should be:txtDataReceived.AppendText(txtDataToSend.Text);Of course, you didn't say what object txtDataReceived is, so I'm just guessing here.
30 Jan 2010 by #realJSOP
You voted my answer a 1 because I pointed out a spelling mistake and your lack of information required to help you solve the problem?Oh yeah, you still haven't mentioned WHAT the error is (and the appropriate term is "exception").It'll probably throw an exception if the Text property...
31 Jan 2010 by #realJSOP
Not that you've posted the error message you're getting, I googled "C# TextBox object", and on the MSDN site, I found that TextBox.AppendText() is not available until you use .Net 3.5 or higher.You're using .Net 3.0...The error message is telling you that the method simply isn't in the...
1 Feb 2010 by #realJSOP
The "update option" can be implemented via the "Click Once" feature in the IDE, and creating a shortcut is part of the installation of the app, but the rest requires coding or 3rd-party components. There is no one link you can be pointed to. Use google to find the specific components that...
5 Feb 2010 by #realJSOP
You have to a) know the organization/contents of the schema, and b) manually create an object that reflects that schema. At that point, you can deserialize the XML into an instance of object.EDIT ==========You could also create a dataset from xml.
10 Feb 2010 by #realJSOP
One of two things happened. 0) "DBCN" doesn't exist in app.config. Remember that property names are case-sensitive - could it be that your have used "DbCN" or something along those lines?1) The property you're using exists in app.config, but doesn't have a value.Either find out...
11 Feb 2010 by #realJSOP
This homework assignment has been just about beat to death here. If you search the C# forum, you'll find the answer.
15 Feb 2010 by #realJSOP
Ummmm, shouldn't the name of the property in the class be the name of the XML element/attribute you want?
22 Feb 2010 by #realJSOP
If your service has stopped, none of the timer code will be running. If you want to do that, you're going to have to write a desktop (systray) application that performs the act of restarting your service.The bigger quetion is this - why did your service stop in the first place? An...
3 Mar 2010 by #realJSOP
In IIS, you need to set permissions on the web app/virtual directory.
5 Mar 2010 by #realJSOP
Unless you have a mail server on your local box, that won't work.You probably also need some credentials (userID/password) to send/read mail on your mail server. If you don't need those things, you have no business running a mail server that's exposed to the internet.Lastly, turn off...
6 Mar 2010 by #realJSOP
Add a boolean variable indicating that the query is to be run, and use a switch statement instead of if/else.bool executequery = true;DataTable dt = null;string Query = "";switch (mainid){ case 1 : Query = "blah blah"; break; case 2 : Query =...
6 Mar 2010 by #realJSOP
What do you mean by "use the MdiParent property"?Put a dot after it and do what you want. Of course, you're probably going to have to cast the property to the desired class in order to do anything app-specific.The correct way to do it is for the MdiParent form subscribe to the user...
7 Mar 2010 by #realJSOP
Try this:int index = DdList.FindExactString(CellText.ToString());if (index >= 0){ DdList.SelectedIndex = index;}else{ // handle the fact that DdList doesn't contain the string}
10 Mar 2010 by #realJSOP
You're going to have to write a lot of custom code to get that to happenn. I would create new classes inherited from the controls you want to be able to resize, and go from there.Maybe there's something already out there that does this, too.Google is your friend.I found this right...
14 Mar 2010 by #realJSOP
First, you don't need the variable f - you'll see why in a moment.Second, your BackgroundWorker object should support cancellation so that it cleans up correctly if the user does something to dismiss the form while the worker is busy.The while statement should look something like...
19 Mar 2010 by #realJSOP
Well, I googled "develop ms office addins" and got over 675,000 hits. Maybe the answer is there.
19 Mar 2010 by #realJSOP
If it were me, I'd change the protection level (if necessary) on the internal UserControl, and then subscribe to the appropriate event from the main form.private void Load(){ this.userControl.innerUserControl.Button.Click += ....}I know, it's not very OOP-centric to expose...
27 Mar 2010 by #realJSOP
You do know that the serial number changes every time you reformat the drive, right?
30 Mar 2010 by #realJSOP
Look at the DirectoryInfo.GetFiles() method. It does exactly what you need (returns an array of strings that represents the file names that exist in the folder in question.
1 Apr 2010 by #realJSOP
The Parent property of a form isn't automatically set by the framework. You have to do it manually.Once you do that, you can retrieve the form's title by retrieving this.Parent.TextEDIT ========Don't post both here AND the C# forum. It's enough to ask in just one of those two places.
11 Apr 2010 by #realJSOP
Someone else asked the same question last week (or maybe the week before). I don't recall the specifics, but there's actually an API for that (if we're talking about Windows Mobile/Phone).Google is your friend.
11 Apr 2010 by #realJSOP
Just have the application itself be responsible for creating the database. It can check to see if it exists before trying to create it when it starts up.
21 Apr 2010 by #realJSOP
Don't repost the same question a second time.
22 Apr 2010 by #realJSOP
Well, it looks like you have all of the information you need to debug the problem. It might be easier if you take all the code and put it into a console app so it's easier to run through the debugger.
10 Jul 2014 by #realJSOP
Extension methods can help you avoid sticky situations.
28 Apr 2010 by #realJSOP
You can do it pretty much the same way. In fact, the code should pretty much be able to be dropped in exactly the way you already have it (with the appropriate variable name change for the treeview itself).
4 May 2010 by #realJSOP
This is - well - impossible. The only way you can resolve the issue is to force the machine to start in safe mode, and you can only really do that as it's booting up.At that point, you can manually examine the various system logs and try to find the issue.In short, writing an app to...
9 May 2010 by #realJSOP
I would load the available manufacturers into a list and compare the contents of the textbox to the list. If it doesn't find a match, an error message is generated. Of course, you could eliminate that process altogether by providing a drop down that contains what's in the list, and allow the...
11 May 2010 by #realJSOP
Use a hashtable that contains the unique characters from string 1, and then you only need to try adding characters from string 2 and count the number of times you get an exception (happens when you try to add an item that already exists in the hashtable).That's the first way I thought of....
13 May 2010 by #realJSOP
That's a non-standard interface. The whole point of Windows is to provide a common interface for all applications. The only way you could accomplish this is by eating the tab event, and handling the enter key event by manually determining which control to move to by examining the tab order...
13 May 2010 by #realJSOP
Well, you could use a cookie and store it on the person's machine, but that could be defeated if they use another machine.Essentially you can't really control what a user does unless a) he's not registered or b) you make him log in first. Once logged in, any number of mechanisms could be...
16 May 2010 by #realJSOP
I absolutely abhor using regex, but it really is the best tool for the job in this case://--------------------------------------------------------------------------------public static bool ValidEmailAddress(string addy){ bool valid = true; string pattern =...
17 May 2010 by #realJSOP
Well then, the obvious answer is that you're doing something wrong in the web page. Are your parameters (if any) correct? Are you calling the correct stored procedure? How are you calling the stored proc from the web page? What exception is being returned?Your question is so vague that we...
21 May 2010 by #realJSOP
If it's a collection of complex objects (versus simple intrinsic types), you could create a property that can returns the objects as XElements, or you could use XML serialization. I personally prefer the property approach.If they're not complex types, you could write extension method...
24 May 2010 by #realJSOP
You either derived from IDisposable and didn't provide the necessary methods for the interface, or you're calling a method that simply doesn't exist at all, or doesn't have the same return type and/or parameter list.
24 May 2010 by #realJSOP
When you have a question for a specif person about a specific article DO NOT use Quick Answers to ask your question. There is a forum attached to every article (look at the bottom of the article web page).For god's sake, pay attention to what you're doing. That's a hallmark of being a...
27 May 2010 by #realJSOP
What do you mean by "hidden data"? Do you mean a hiden file attachment, or hidden data in the email text? Either way, I have to ask why you want to do this because to be honest, your request doesn't pass the smell test.
2 Jun 2010 by #realJSOP
You could add a property to your object that returns a XElement which contains the properties you're interested in. I think it's a lot more straightforward than serializing. I do it all the time.
11 Jun 2010 by #realJSOP
I seem to remember trying to find the same info on this, and like you, found nothing. I don't think it can be done. You're going to have to come up with your own control if you want to make it configurable.
17 Jun 2010 by #realJSOP
You have more control over what's happening with method #2. That's the one I would choose. However, don't forget to add the requisite try/catch/finally block to handle any exceptions that might occur.
20 Jun 2010 by #realJSOP
Maybe you forgot to close the file (a thread might still be holding it open, and you didn't properly terminate the thread?). Make sure your app isn't still running (use Task Manager).
22 Jun 2010 by #realJSOP
This codeproject article will explain it to you:Abstract Class versus Interface[^]
3 Jul 2010 by #realJSOP
You've provided so little information that we can't possibly help you.
9 Jul 2010 by #realJSOP
I wrote a tip that applies to retrieving data from a web service, but you could easily convert the concept to your specific (and poorly stated) needs (including writing to the database).Pass Dynamic List of Parameters to Web Service[^]
15 Jul 2010 by #realJSOP
What that means is that you have to use an account on that server in order to send emails. "Relay" is tha act of letting someone use your server with a "from" address that is not found on the server.
19 Jul 2010 by #realJSOP
There's at least one free library available that does what you need. Just google for "C# zip files" or something more appropriate.
20 Jul 2010 by #realJSOP
So create the necessary session vars and be done with it.
23 Jul 2010 by #realJSOP
Did you check with the manufacturer?
24 Jul 2010 by #realJSOP
Iterate through the open forms like this:foreach (Form form in Application.OpenForms){ if (form is frmMaster) { // do something break; }}A little googling would have saved you months of time...
2 Aug 2010 by #realJSOP
This looks like a homework assignment, and we don't generally do homework for people here. However, that thought hand't occurred to me before I came up with the answer, so consider yourself lucky thata you got a response at all.FWIW, you should find another isntructor because he's not teaching...
3 Aug 2010 by #realJSOP
Custom app.config[^]
10 Aug 2010 by #realJSOP
Right click the desired project in the solution explorer, and select "Set as Startup Project" from the context menu.
10 Aug 2010 by #realJSOP
var max_value = (from item in arrayList select item.countPoint).Max();Google would have helped you faster.
11 Aug 2010 by #realJSOP
Try this.var max_value = (from PointOnLine item in arrayList select item.countPoint).Max();You've had several suggestions on how to approach your problem. Be a programmer and figure it out. Nobody here is going to sit down and write code to figure it out for you. We...
13 Aug 2010 by #realJSOP
Memory address in .Net aren't static. Objects get moved around all the time by the memory manager. What are you trying to accomplish?
13 Aug 2010 by #realJSOP
You need to add a return statement at the bbottom of the method that retuns an int. I recommend returning a 0.
16 Aug 2010 by #realJSOP
In Visual Studio, add a setup project to your solution.
19 Aug 2010 by #realJSOP
Establish a FileSystemWatcher to watch for the file change event, and when you detect one, start a thread that processes that file. You can even use a thread pool to manage the whole process.Be a programmer. It doesn't hurt. Really.
21 Aug 2010 by #realJSOP
You want to handle the InstanceCreationEvent and InstanceDeletionEvent events. Then use WMI to determine what changed.
21 Aug 2010 by #realJSOP
Did you even have a twinkle of a thought of using google to find sample code?I googled "linq to xml sample", and found this site among over 1.2 MILLION hits.http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx[^]
25 Aug 2010 by #realJSOP
It sounds like you're trying to update the DLL dynamically (while the web site is running). Try closing your browser, reopening it, and browsing back to the web site where the DLL is, and see if it reveals the new methods.There may be a way to force an assembly to reload, but I don't know...
25 Aug 2010 by #realJSOP
Application.Op...
26 Aug 2010 by #realJSOP
When you retrieve it, have the stored procedure strip the character from the strings, or when you save it, strip the character before you update the database.
7 Sep 2010 by #realJSOP
I Want how to add listbox items into another listbox. listbox2.Items.AddRange(listbox1.Items);How to send that listbox fields send to receiver. Write them all down on a piece of paper, hand them to a runner, and say "Quick! Get this to the receiver!".I want full code. This...
16 Sep 2010 by #realJSOP
You could also set up a global static class that contains an event that fires when a property is changedand handle that event in the desired form.
24 Sep 2010 by #realJSOP
Google "WriteableBitmap object", and/or "real-time image editing with silverlight".
24 Sep 2010 by #realJSOP
Use the int.TryParse method. It returns a bool that indicates if it was a valid integer so that you don't have to rely on the try/catch mechanism (there's really no point in throwing an exception when you can otherwise easily enough verify/react to the expected results.
6 Oct 2010 by #realJSOP
Well, the first line is getting the list from a method somewhere, and you're just assuming thast the returned list is a) not null, and b) has items.I would put if (list != null) after the first line, and only perform further processing if there's a reason to do so.
6 Oct 2010 by #realJSOP
Create a new solution in Visual Studio, and start coding.
12 Oct 2010 by #realJSOP
All of the above answers are close, but unless you're handling the TextChanged event to ensure that only numeric values are entered as the user types, you could run into problems.I would do this:double x1;double x2;if (double.TryParse(textBox1.Text, out x1) &&...
13 Oct 2010 by #realJSOP
Looks like you misspelled "Job_Title".
19 Oct 2010 by #realJSOP
If you're asking whether or not you cand tell if a local file/folder is shared, no, I don't think you can.If you're asking if you can tell if a given remote folder/file is a share, yes you can. You can even determine if it's a connected share, and what the permissions are. I'm pretty sure...
28 Oct 2010 by #realJSOP
Change the 3rd parameter to FileAccess.ReadWrite.Change the last parameter to System.IO.FileShare.None. Once you open the file with your app, no other file can open the file.
28 Oct 2010 by #realJSOP
1) Yes, you can iterate network drives as well. You may have to use WMI to get the shares, but it should be possible.2) I don't know if the best or not, because I've never wanted to do anything like this.3) I would use linq to write it to a xml file4) Just, ummm, encrypt it....
10 Nov 2010 by #realJSOP
Try this:List queryT = null;queryT = (from proc in DataContext.Procedimentos join ass in DataContext.Assistencias on proc.assistencia equals ass.codigo join mac in DataContext.Maquinas on ass.maquina equals mac.SN where ass.maquina == maq.SN ...
19 Nov 2010 by #realJSOP
Create a bitmap with the desired color depth as the destination bitmap and copy the original image to it.
28 Nov 2010 by #realJSOP
Just declare the delegate as public in a static class in the assembly, and you can use them anywhere that uses that assembly.
3 Dec 2010 by #realJSOP
The only way to prevent the user from deleting a folder is by having a file in that folder opened by a process (I think setting a file in the folder to be read only may also work). Caveat: When you delete a folder, the file system first tries to delete files in the folder, and when all of...
7 Dec 2010 by #realJSOP
You could just have the client app periodically check to see if the server app is running...
9 Dec 2010 by #realJSOP
Maybe this will help:http://blogs.msdn.com/b/charlie/archive/2006/11/19/linq-farm-group-and-distinct.aspx[^]EDIT==================I don't understand why this was voted 1...
8 Dec 2010 by #realJSOP
You can't change the iterator used in a foreach statement because it's read-only.What you could do is create a property that indicates "used", use Linq to build a collection of items that aren't "used", and then use foreach on that new collection.