58 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for tinstaafl

Basically this scheme uses variable offsets, but it generates the bytes on the fly. They aren't truly random, but there aren't any obvious patterns and the output passes all the NIST tests. Since a simple password can be used to do the de/encryption it is much easier to hand off …

Member Avatar for JamesCherrill
2
330
Member Avatar for ddanbe

Well, there was a thread about a frequency function and a bell curve in Excel. [url]http://www.daniweb.com/forums/thread295203.html[/url] So here it is how about to do the NORMDIST function in Excel in C#.

Member Avatar for dlhockey12
0
3K
Member Avatar for tinstaafl

There are times when you need to make sure your counter starts at an odd or even number. Even is pretty simple - `counter = counter + modulus(counter)`. If counter is even it stays, if it's odd it gets incremented by 1. Odd is a bit more complicated - `counter …

Member Avatar for holisticgroup19
3
4K
Member Avatar for ddanbe

Sometimes you have long processes and you even want display them up to the millisecond. Here is a way to do it.

0
1K
Member Avatar for ddanbe

[OH noo, please not that again!](https://www.youtube.com/watch?v=DvShTJKuy2w) Yeah, primes sigh. But they play a minor role here as a perfect victim to explain some other things. Would not advise to use the algorithm here to calculate them in real life. There are languages like Python, F#, Haskell etc. who have list …

Member Avatar for ddanbe
0
376
Member Avatar for Lusiphur

As it seems to come up often enough I figured I'd throw together a quick snippet outlining basic methods for data manipulation in SQL Server using C#. In all examples the coder will need to substitute their own connection string details and variables. I utilised parameters for 3 of the …

Member Avatar for sarvesh_3
2
21K
Member Avatar for ddanbe

This is easy! But I admit, it can be rather confusing at first if you also take the old style MenuItem stuff into account. I hope my code is as clear as possible. If not please let me know. To test it, just start a forms application and paste it …

2
6K
Member Avatar for ddanbe

One of the most, if not THE most, beautiful formulas in math, is from Euler: ![Euler_e_pi_i.png](/attachments/large/1/b32f45540a27b3efc328d14c60ee286c.png "align-center") It combines in it a relation between the number **e**, the number **Pi** and the complex number **i**, plus the basic math symbols 1, +, = and zero. Is that not amazing? More …

Member Avatar for JOSheaIV
1
616
Member Avatar for tinstaafl

This is a very simple login form. I set it up so that the form won't close until it's cancelled or a valid username and password are entered. I chained the check for the username and the check for the password, so that if the username doesn't pass the password …

Member Avatar for tinstaafl
0
7K
Member Avatar for TrustyTony

I did code for challenge that I saw posted for C# by deceptikon: http://www.daniweb.com/software-development/csharp/threads/479304/coding-challenge-string-to-date Here it is. Of course normally the code would be without prints and put in function, but this is enough for now for me. There could also be normalization from '/' separated form not producing ambiguous …

1
269
Member Avatar for sknake

Here is a sample code snippet of logging in a user against a user table in an MSSQL database with password encryption. Scott Knake

Member Avatar for pritaeas
10
8K
Member Avatar for ddanbe

Don’t know if this is ever been done before, or even if it is a good way to do it. I’ll just await your comments if any. What I mostly found on the web is that if you want to define a polynomial you need to have an array containing …

0
448
Member Avatar for ashishkumar008

[B]1.[/B] Right click on your project name in solution explorer. [B]2.[/B] Point the cursor on [COLOR="Green"]Add[/COLOR] then choose [COLOR="Green"]Existing Item...[/COLOR] [B]3.[/B] Now go to the Location of your sound file and select that sound file. [B]4.[/B] Now select your sound file in solution explorer then Right click on it choose …

Member Avatar for JOSheaIV
3
5K
Member Avatar for ddanbe

Yes, I know Fibonacci(=sun of a good man) again. Most famous for his series, but who among you all, know that he was the man who introduced to the Western world, the Arabic numeral system(including zero) in 1202 A.D.? The Italian merchands of those days adored it. It was far …

Member Avatar for Triryche
2
580
Member Avatar for ddanbe

The luxuries we now have in the amount of pixels on a screen to draw some amazing graphs with, were lacking in the early days of computing. Most of the time you had to resort to rude printed output. It wasn’t that bad always. Sometimes it was and still is …

Member Avatar for ddanbe
1
3K
Member Avatar for riahc3
Member Avatar for vegaseat

This short piece of code shows you how to display text in color in a C# windows console program. The corresponding WIN32 API functions are in the kernel32.dll and are imported and declared external. The only other problem is to assign variable types that accommodate the types listed in the …

Member Avatar for KrayZVIII
0
1K
Member Avatar for vinayphadke

Hello Guys, I was performing text file reading and writting operations and the job looked very simple as usual, yet it has not been solved successfully. We have got a simple text file **final.txt** which contains data like this:- **05/18/2012 02:12:66 8HRY hjhruehr737243 YES NO u34gewryge 698** i.e each value …

Member Avatar for gnath
0
265
Member Avatar for sandeepparekh9

Ever Thought if it was possible to not WebBrower control and use the Firefox Browser in your c# window Application...?? Yes ,, It is possible using GeckoFx wrapper class for C#.net and vb also. You will need the Followings: 1. [URL="http://code.google.com/p/geckofx/downloads/list"]GeckoFx Wrapper[/URL] 2. [URL="http://mirrors.directorymix.com/mozilla/xulrunner/releases/1.9.1.2/runtimes/"]Xul Runner[/URL] (Download the zip file from …

Member Avatar for newlonator
0
934
Member Avatar for ddanbe

While surfing the web I got to this site: [url]http://en.wikipedia.org/wiki/Fourier_series[/url] “Hey, I why not write something like this in C#!” The rather scary looking formulas did not withhold me to start coding (see below Fig. 1 and Fig. 2) The formula from Fig. 2 is hidden under one of the …

Member Avatar for skatamatic
0
3K
Member Avatar for ddanbe

When you want to draw something on a form you need a Graphics object. But a Graphics constructor isn’t public and if that is not enough the Graphics class is also sealed! This means you can’t create a Graphics object via the new keyword nor can you derive from the …

Member Avatar for skatamatic
0
4K
Member Avatar for vegaseat

Is it Mother Date and Father Time? Any way, getting all the different date and time displays working can be imperturbably perplexing at times. You take a look at it in this Windows Console Application.

Member Avatar for Tsawm
0
970
Member Avatar for Mahen
Member Avatar for ddanbe

What polar coordinates are is explained [url=http://en.wikipedia.org/wiki/Polar_coordinate_system]here[/url]. I wanted to draw some polar functions myself, so I changed my [url=http://www.daniweb.com/software-development/csharp/code/217204]plotting class [/url] a bit and added a polar struct to a new project.. Just posted code for the Plot class and the polar point structure here. You can find an …

2
1K
Member Avatar for ddanbe

I saw a thread lately on this site to rotate an integer. Seemed like a fun project to do. There are probably more efficient solutions out there but this is mine, and indeed it was fun! It is mostly a demo on how you could use the less known shift …

Member Avatar for kel634
0
2K
Member Avatar for ddanbe

I find C# very well suited for doing math and all sorts of calculations, so here is an example. Just start a Console application and fill in the code. Have fun! The code also shows a use of delegates and some Console functions. If you don't know what the Newton-Raphson …

0
3K
Member Avatar for zinnqu

Using the Load and Unload events of the Forms add these subs to handle a simple fade in and out effect. This is not limited to just one form. The subroutine definition can be added to any global class allowing the use on any form or sub-form. This is the …

Member Avatar for CsharpChico
1
2K
Member Avatar for Xcelled194

One of the things that always irked me about C# is its lack of an InputBox function. In VB, You can simply do [CODE=VBNET]response = InputBox("Enter your name")[/CODE] Unfortunately, there is no C# equivalent. Sure, you can call the VB one, but doesn't that kind of defeat the purpose of …

2
1K
Member Avatar for vegaseat

I am afraid, I am starting to like C#, despite the somewhat bloated .Net Framework requirements. Mister Bill's Microsoft is very supportive though. The language has a nice flow compared to GUI programming in C++. Here we are looking at a standard ListBox, add some items, sort them and select …

Member Avatar for anucom
0
714
Member Avatar for PsychoCoder
Member Avatar for PsychoCoder

C# code snippet demonstrating how to set the status of a specified Windows service. Provide the name of the service and it's value (it's an integer value described in the comments)

0
769
Member Avatar for PsychoCoder

This is a snippet that will get either all the child controls of a form (other other control) or controls of a specified type. This is for C# 4.0 as it utilizes an optional parameter.

0
3K
Member Avatar for Duki

I've spent the last couple of days researching how to connect to a database server and modify the data in that server. I was able to find a lot of information on how to Read from a database, but I found very little material to assist with Writing to a …

Member Avatar for Duki
0
821
Member Avatar for subcom

[B]Introduction[/B] In this sample,It shows how to move files to another folder. [B]Background[/B] It can be used in winForm applications.

Member Avatar for logiccool
0
3K
Member Avatar for sohil.shivani

Hello sir, I tried with this code it is running well but I am not getting mail in my account with this code, even this code is not giving any error. Is there any problem?? Please help me.

0
489
Member Avatar for vegaseat

A small Windows Application to show you how to play a wave (.wav) sound file. I am using the C# IDE from SharpDevelop and the runtime dotnetfx 1.1 from Microsoft, both free downloads. This forms a small and fast student system to write and debug C# programs. From there you …

Member Avatar for ashley dane
0
1K
Member Avatar for ddanbe

Although there is little need for any sort algorithm in C#. Every collection class has a sort method, so why would you wanna write one for yourself? My guess to learn and see how it is done. Well her are implementations of two popular sorts. The arrays are integer but …

Member Avatar for subtercosm
0
837
Member Avatar for ddanbe

Visual Studio is a great tool to use. But for beginners like me a few years back, it was a bit overwhelming and confusing. You got the feeling you lost all the control. VS has it’s special ways of doing things with partial classes and so on. So lets get …

0
150
Member Avatar for ddanbe

Encryption has many issues. It can be very simple or very complex. I personally don’t have that many secrets, but when the company I worked for wanted to encrypt something I used the following : XOR ! What is nice about xor is that you can use the same method …

Member Avatar for Ramy Mahrous
0
596
Member Avatar for ddanbe

Class to convert between Celcius, Fahrenheit and Kelvin temperatures. Set one temperature and automatically get the other two. This class makes use of properties. See the code snippet for details. A short main program is added to exercise the Temperature class by printing a conversion table between celsius and fahrenheit.

Member Avatar for ddanbe
0
2K
Member Avatar for ddanbe

If you ever want to get information about files stored in a particular map or directory, you can find out how it is done here. With a little modification you could turn this snippet into a DOS DIR-command or a UNIX(LINUX?) ls-command.

0
220
Member Avatar for ddanbe

[TEX]Solve an equation of the form Ax^2 + Bx + C = 0.[/TEX] The class is commented, but if you have any questions don't be affraid to ask. You may exercise this class in a console application with the following snippet : [CODE]QuadraticEquation z = new QuadraticEquation(1, 3, 3); z.Solve(); …

0
781
Member Avatar for toraj58

[B]Sometimes it is good to sit back and reflect on life[/B]. More specifically, you can sit back and reflect on yourself. Often you will discover information that you didn’t realize about yourself. [B]it is possible to have a C# program reflect upon itself.[/B] You can use such reflection to learn …

0
149
Member Avatar for subcom

[B]Introduction[/B] We can use Microsoft SOAP protocol to transfer any files between client and server.It's easy through firewall and also it cross flatform. [B]Background[/B] I was going to develop an mobile software on pocket pc,but I found there were tiny resouces to use on mobile operating system.finally,I was finding Web …

0
544
Member Avatar for subcom

[B]Introduction[/B] We can use INI file to auto generate the database connection string. [B]Background[/B] It can be used in Webform and winForm.

Member Avatar for sneekula
0
347
Member Avatar for Shalvin

Serialization is the process of saving the state of an object into persistant medium. BinaryFormatter class is used for serializing and deserializing an object. HybridDictionary is optimized for key-based item retrieval from both small and large collections.

Member Avatar for belynmoon
0
261
Member Avatar for Shalvin

Though .Net classes are vast and versatile at time you will have to resort to Win32 API calls for accomplishing certain tasks. The following code shows a simple example of invoking a Win32 api. The best way to use Win32 apis is to encapsulate it in a class module. The …

0
468
Member Avatar for Shalvin

TreeView was one of my favourite control in COM. It is well suited for creating Chart of Accounts, Hierarchical data and the like. Though there is a tree view in .Net I find it less flexible in comparison to COM TreeView. The issue with using COM TreeView in C# is …

0
227
Member Avatar for vegaseat

A short C# code snippet to get the US Naval Observatory Master Clock Time from: [URL]http://tycho.usno.navy.mil/cgi-bin/timer.pl[/URL] The snippet displays the raw HTML code with the time infomation and then extracts one specific US time zone.

Member Avatar for Mustafa Laith
0
684
Member Avatar for vegaseat

The End.