58 Reusable Code Snippet Topics
Remove Filter ![]() | |
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 … | |
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#. | |
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 … | |
Sometimes you have long processes and you even want display them up to the millisecond. Here is a way to do it. | |
[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 … | |
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 … | |
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 … | |
One of the most, if not THE most, beautiful formulas in math, is from Euler:  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 … | |
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 … | |
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 … | |
Here is a sample code snippet of logging in a user against a user table in an MSSQL database with password encryption. Scott Knake | |
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 … | |
[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 … | |
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 … | |
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 … | |
RestSharp library needed | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
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. | |
Note This app will tell the current Time, requires .net 3.0 ![]() | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
This snippet takes a string as input and formats it to proper case | |
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) | |
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. | |
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 … | |
[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. | |
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. | |
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 … | |
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 … | |
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 … | |
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 … | |
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. | |
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. | |
[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(); … | |
[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 … | |
[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 … | |
[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. | |
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. | |
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 … | |
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 … | |
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. | |
Just a quick look at the way C# writes and reads text files. |
The End.