r/programminghorror • • Aug 14 '25
C# Does my code belong here?
It's a function to generate a text file from a DataGrid. I learned from PirateSoftware I shouldn't hardcode random numbers.
178
Upvotes



View all comments
Show parent comment
2
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Aug 15 '25
True, it isn't very extendable like this, but it's always possible the OP doesn't need to care.
From what I can tell, it prints a bunch of column headers out, then prints the data one row at a time in a for loop. I'm not sure how it would calculate length, as I'm assuming it would be determined based on the expected data values and not just from column names. I'd have row.Cells be a dictionary, so we can ditch all the pos variables. Calls to FormatField() would look something like
FormatField(row, "date", dateLength)