Click here to Skip to main content
15,887,881 members
Home / Discussions / C#
   

C#

 
QuestionIs this madness? The pursuit of single-statement methods Pin
Kevin Li (Li, Ken-un)4-Jul-17 10:13
Kevin Li (Li, Ken-un)4-Jul-17 10:13 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
PIEBALDconsult4-Jul-17 10:21
mvePIEBALDconsult4-Jul-17 10:21 
SuggestionRe: Is this madness? The pursuit of single-statement methods Pin
Richard Deeming4-Jul-17 11:09
mveRichard Deeming4-Jul-17 11:09 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Pete O'Hanlon5-Jul-17 4:44
mvePete O'Hanlon5-Jul-17 4:44 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Marc Clifton4-Jul-17 11:26
mvaMarc Clifton4-Jul-17 11:26 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Bernhard Hiller4-Jul-17 21:31
Bernhard Hiller4-Jul-17 21:31 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
ScottM14-Jul-17 22:49
ScottM14-Jul-17 22:49 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Pete O'Hanlon5-Jul-17 1:08
mvePete O'Hanlon5-Jul-17 1:08 
One minor point, you could avoid the StringBuilder in your first example with the use of string.Join. I'm not saying you should, just that you could.
C#
SortedSet<string> seen = new SortedSet<string>();
foreach (string line in longString.Split('\r', '\n'))
{
  seen.Add(line);
}
return string.Join(Environment.NewLine, seen);
If you're interested, this returns this IL:
.maxstack 5
.locals init (
    [0] class [System]System.Collections.Generic.SortedSet`1<string> seen,
    [1] string[] strArray,
    [2] int32 num,
    [3] string line,
    [4] string str)
L_0000: nop
L_0001: newobj instance void [System]System.Collections.Generic.SortedSet`1<string>::.ctor()
L_0006: stloc.0
L_0007: nop
L_0008: ldarg.1
L_0009: ldc.i4.2
L_000a: newarr char
L_000f: dup
L_0010: ldc.i4.0
L_0011: ldc.i4.s 13
L_0013: stelem.i2
L_0014: dup
L_0015: ldc.i4.1
L_0016: ldc.i4.s 10
L_0018: stelem.i2
L_0019: callvirt instance string[] [mscorlib]System.String::Split(char[])
L_001e: stloc.1
L_001f: ldc.i4.0
L_0020: stloc.2
L_0021: br.s L_0035
L_0023: ldloc.1
L_0024: ldloc.2
L_0025: ldelem.ref
L_0026: stloc.3
L_0027: nop
L_0028: ldloc.0
L_0029: ldloc.3
L_002a: callvirt instance bool [System]System.Collections.Generic.SortedSet`1<string>::Add(!0)
L_002f: pop
L_0030: nop
L_0031: ldloc.2
L_0032: ldc.i4.1
L_0033: add
L_0034: stloc.2
L_0035: ldloc.2
L_0036: ldloc.1
L_0037: ldlen
L_0038: conv.i4
L_0039: blt.s L_0023
L_003b: call string [mscorlib]System.Environment::get_NewLine()
L_0040: ldloc.0
L_0041: call string [mscorlib]System.String::Join(string, class [mscorlib]System.Collections.Generic.IEnumerable`1<string>)
L_0046: stloc.s str
L_0048: br.s L_004a
L_004a: ldloc.s str
L_004c: ret

This space for rent

AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Pete O'Hanlon5-Jul-17 4:20
mvePete O'Hanlon5-Jul-17 4:20 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Rob Philpott5-Jul-17 23:22
Rob Philpott5-Jul-17 23:22 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Pete O'Hanlon6-Jul-17 0:04
mvePete O'Hanlon6-Jul-17 0:04 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Gerry Schmitz5-Jul-17 5:13
mveGerry Schmitz5-Jul-17 5:13 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
jschell5-Jul-17 6:28
jschell5-Jul-17 6:28 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Eddy Vluggen5-Jul-17 7:56
professionalEddy Vluggen5-Jul-17 7:56 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
BillWoodruff6-Jul-17 0:03
professionalBillWoodruff6-Jul-17 0:03 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Rob Philpott6-Jul-17 0:26
Rob Philpott6-Jul-17 0:26 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
BillWoodruff6-Jul-17 0:55
professionalBillWoodruff6-Jul-17 0:55 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Richard Deeming6-Jul-17 1:30
mveRichard Deeming6-Jul-17 1:30 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
BillWoodruff6-Jul-17 2:29
professionalBillWoodruff6-Jul-17 2:29 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Rob Philpott6-Jul-17 3:22
Rob Philpott6-Jul-17 3:22 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Richard Deeming6-Jul-17 3:28
mveRichard Deeming6-Jul-17 3:28 
QuestionRe: Is this madness? The pursuit of single-statement methods Pin
BenScharbach12-Aug-17 9:48
BenScharbach12-Aug-17 9:48 
Questionhi Pin
Member 132829294-Jul-17 9:39
Member 132829294-Jul-17 9:39 
AnswerRe: hi Pin
Pete O'Hanlon4-Jul-17 10:53
mvePete O'Hanlon4-Jul-17 10:53 
AnswerRe: hi Pin
BenScharbach12-Aug-17 9:51
BenScharbach12-Aug-17 9:51 

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.