Click here to Skip to main content
13,773,358 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Bernhard Hiller18-Mar-18 23:42
memberBernhard Hiller18-Mar-18 23:42 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 3:31
mvpraddevus19-Mar-18 3:31 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Super Lloyd19-Mar-18 3:29
memberSuper Lloyd19-Mar-18 3:29 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 3:32
mvpraddevus19-Mar-18 3:32 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Super Lloyd19-Mar-18 3:42
memberSuper Lloyd19-Mar-18 3:42 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming19-Mar-18 3:44
mvpRichard Deeming19-Mar-18 3:44 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Super Lloyd19-Mar-18 3:48
memberSuper Lloyd19-Mar-18 3:48 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 4:56
mvpraddevus19-Mar-18 4:56 
Ohh...look...I've really gone crazy with this now.

public static class Helper{
	public static T Tee<T>(
	this T @inVal,
	Action<T> act){
		act(@inVal);
		return @inVal;
	}
	
	public static Byte[] GetBytes( this String @inVal){
		Byte [] outBytes = new Byte[@inVal.Length];
		int loopCount = 0;
		foreach (Char c in @inVal){
			outBytes[loopCount] = Convert.ToByte(c);
			loopCount++;
		}
		return outBytes;
	}
	
	public static String DisplayBytes(this byte[] inBytes){
		String outVal = String.Empty;
		foreach (Byte b in inBytes){
			outVal += Convert.ToString($"{b} ");
		}
		return outVal;
	}
}


Try it like this and you get before and after again:
"What up!"
		.Tee(Console.WriteLine)
		.GetBytes()
		.DisplayBytes()
		.Tee(Console.WriteLine);


Output looks like:

What up!
87 104 97 116 32 117 112 33

Cool | :cool:
Well, it's fun.
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 5:09
professionalEddy Vluggen19-Mar-18 5:09 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 5:13
mvpraddevus19-Mar-18 5:13 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 5:18
professionalEddy Vluggen19-Mar-18 5:18 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 6:46
mvpraddevus19-Mar-18 6:46 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 7:16
professionalEddy Vluggen19-Mar-18 7:16 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 8:23
mvpraddevus19-Mar-18 8:23 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 9:03
professionalEddy Vluggen19-Mar-18 9:03 
GeneralOFFTOPIC Pin
Nelek19-Mar-18 8:00
protectorNelek19-Mar-18 8:00 
GeneralRe: OFFTOPIC Pin
raddevus19-Mar-18 8:21
mvpraddevus19-Mar-18 8:21 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sander Rossel20-Mar-18 6:52
professionalSander Rossel20-Mar-18 6:52 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus20-Mar-18 8:24
mvpraddevus20-Mar-18 8:24 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming20-Mar-18 8:32
mvpRichard Deeming20-Mar-18 8:32 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus20-Mar-18 9:24
mvpraddevus20-Mar-18 9:24 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sander Rossel21-Mar-18 2:38
professionalSander Rossel21-Mar-18 2:38 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus21-Mar-18 3:40
mvpraddevus21-Mar-18 3:40 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming19-Mar-18 9:26
mvpRichard Deeming19-Mar-18 9:26 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 9:40
mvpraddevus19-Mar-18 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.181119.1 | Last Updated 22 Nov 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid