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

C#

 
JokeRe: include a file Pin
Big Daddy Farang27-Apr-12 10:05
Big Daddy Farang27-Apr-12 10:05 
AnswerRe: include a file Pin
VJ Reddy27-Apr-12 5:03
VJ Reddy27-Apr-12 5:03 
AnswerRe: include a file PinPopular
PIEBALDconsult27-Apr-12 5:32
mvePIEBALDconsult27-Apr-12 5:32 
GeneralRe: include a file Pin
jschell28-Apr-12 7:39
jschell28-Apr-12 7:39 
QuestionC# Media Library Help ! Pin
O.Calderbank27-Apr-12 2:27
O.Calderbank27-Apr-12 2:27 
AnswerRe: C# Media Library Help ! Pin
Richard MacCutchan27-Apr-12 2:42
mveRichard MacCutchan27-Apr-12 2:42 
AnswerRe: C# Media Library Help ! Pin
Wes Aday27-Apr-12 10:03
professionalWes Aday27-Apr-12 10:03 
QuestionDocument opening/saving idiom Pin
Orjan Westin27-Apr-12 1:07
professionalOrjan Westin27-Apr-12 1:07 
Coming from a C++ background, I'm keen to learn the C# idiom. Picking up the language is simple enough, and I'm finding my way around the class library, but I'm not familiar with the idiom, or "how things are done".

I would like the code I write to follow the conventions well enough that an experienced C# developer reading the code can see what's going on without getting confused about alien idioms.

(One example I've noticed is the use of foreach rather than for loops over collections.)

Now, I have a document class for a desktop application, and I'd write its IO interface like this:

C#
class Document
{
  // Default constructor (eg File->New)
  public Document()
  {}
  // Construct by reading from file (eg File->Open)
  public Document(string path) 
  {}
  // Write document to path it opened from (eg File->Save, after opened or saved once)
  public void Write()
  {}
  // Write document to new path  (eg File->Save As, of first File->Save after default construction)
  public void Write(string path)
  {}
}


I don't think this is idiomatic C# though. Most examples seem to pass in streams instead of path names, for instance, and handle that aspect (eg opening and closing IO streams) outside the document class, in the application. Is that correct? Should I write a separate serializer?

Please let me know what the "proper" C# way of doing things like this is.

Cheers,
Orjan
AnswerRe: Document opening/saving idiom PinPopular
Pete O'Hanlon27-Apr-12 1:57
mvePete O'Hanlon27-Apr-12 1:57 
AnswerRe: Document opening/saving idiom Pin
PIEBALDconsult27-Apr-12 3:22
mvePIEBALDconsult27-Apr-12 3:22 
AnswerRe: Document opening/saving idiom Pin
Eddy Vluggen27-Apr-12 7:04
professionalEddy Vluggen27-Apr-12 7:04 
AnswerRe: Document opening/saving idiom Pin
OriginalGriff27-Apr-12 9:29
mveOriginalGriff27-Apr-12 9:29 
NewsExpand the text in the RichTextBox. Pin
nqs_vn27-Apr-12 0:10
nqs_vn27-Apr-12 0:10 
AnswerRe: Expand the text in the RichTextBox. Pin
VJ Reddy27-Apr-12 1:16
VJ Reddy27-Apr-12 1:16 
GeneralRe: Expand the text in the RichTextBox. Pin
nqs_vn27-Apr-12 16:40
nqs_vn27-Apr-12 16:40 
QuestionSave List with BinaryReader Pin
larsp77726-Apr-12 23:22
larsp77726-Apr-12 23:22 
AnswerRe: Save List with BinaryReader Pin
Wayne Gaylard26-Apr-12 23:44
professionalWayne Gaylard26-Apr-12 23:44 
QuestionWindow Service didn’t run when SQL Server is on Remote Database Pin
masterprogrammertech26-Apr-12 23:17
masterprogrammertech26-Apr-12 23:17 
AnswerRe: Window Service didn’t run when SQL Server is on Remote Database Pin
PIEBALDconsult27-Apr-12 3:24
mvePIEBALDconsult27-Apr-12 3:24 
AnswerRe: Window Service didn’t run when SQL Server is on Remote Database Pin
charlybones7-May-12 22:17
charlybones7-May-12 22:17 
Questionimpresiones en c# Pin
samuelalvarito26-Apr-12 6:42
samuelalvarito26-Apr-12 6:42 
AnswerRe: impresiones en c# Pin
phil.o26-Apr-12 6:48
professionalphil.o26-Apr-12 6:48 
AnswerRe: impresiones en c# Pin
Abhinav S26-Apr-12 7:02
Abhinav S26-Apr-12 7:02 
AnswerRe: impresiones en c# Pin
jschell28-Apr-12 7:44
jschell28-Apr-12 7:44 
Questionspooler en c# Pin
samuelalvarito26-Apr-12 6:40
samuelalvarito26-Apr-12 6: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.