Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
AnswerRe: Programatically determine variable name Pin
Ennis Ray Lynch, Jr.28-May-08 11:02
Ennis Ray Lynch, Jr.28-May-08 11:02 
AnswerRe: Programatically determine variable name Pin
Guffa28-May-08 12:31
Guffa28-May-08 12:31 
QuestionChecking readonly property using reflection? Pin
pankazmittal28-May-08 9:11
pankazmittal28-May-08 9:11 
AnswerRe: Checking readonly property using reflection? Pin
Ed.Poore28-May-08 10:33
Ed.Poore28-May-08 10:33 
QuestionPass Reference or Return Value Pin
Jim Warburton28-May-08 8:24
Jim Warburton28-May-08 8:24 
AnswerRe: Pass Reference or Return Value Pin
Luc Pattyn28-May-08 8:40
sitebuilderLuc Pattyn28-May-08 8:40 
GeneralRe: Pass Reference or Return Value Pin
Jim Warburton28-May-08 8:54
Jim Warburton28-May-08 8:54 
AnswerRe: Pass Reference or Return Value Pin
User 665828-May-08 8:59
User 665828-May-08 8:59 
In my opinion I'd use the non-ref method. The reason is, that many classes in the .NET framework are immutable, like string. Even more important, the DateTime class also uses return values (AddHours, AddMonths, etc.), which means that DateTime objects are immutable, too.

In C# 3.0 you could also use extension methods, for example like this:

public static class DateTimeExtensions
{
    public static DateTime SetToHour(this DateTime source, int hours)
    {
        if ((hours < 0) || (hours > 23))
            throw new ArgumentOutOfRangeException("Hours must be between 0 and 23");

        return source.AddHours(hours - source.Hour);
    }
}


and call it like that:

DateTime t = DateTime.Now;
Console.WriteLine(t);
t = t.SetToHour(24); // cool, we got a new extension method in the .NET DateTime class
Console.WriteLine(t);


regards

modified 12-Sep-18 21:01pm.

GeneralRe: Pass Reference or Return Value Pin
Roger Alsing28-May-08 10:46
Roger Alsing28-May-08 10:46 
GeneralRe: Pass Reference or Return Value Pin
User 665828-May-08 18:45
User 665828-May-08 18:45 
QuestionC# RPC from JAVA Pin
xlthim28-May-08 8:08
xlthim28-May-08 8:08 
AnswerRe: C# RPC from JAVA Pin
Judah Gabriel Himango28-May-08 12:32
sponsorJudah Gabriel Himango28-May-08 12:32 
QuestionFortran DLL in C#? Pin
sharp_k28-May-08 7:34
sharp_k28-May-08 7:34 
AnswerRe: Fortran DLL in C#? Pin
Judah Gabriel Himango28-May-08 12:37
sponsorJudah Gabriel Himango28-May-08 12:37 
QuestionAborting a method in c# Pin
WebMaster28-May-08 7:34
WebMaster28-May-08 7:34 
AnswerRe: Repost Pin
Gareth H28-May-08 7:41
Gareth H28-May-08 7:41 
GeneralRe: Repost Pin
WebMaster28-May-08 7:45
WebMaster28-May-08 7:45 
GeneralRe: Repost Pin
Brady Kelly28-May-08 8:35
Brady Kelly28-May-08 8:35 
GeneralRe: Repost Pin
Thomas Stockwell30-May-08 10:50
professionalThomas Stockwell30-May-08 10:50 
GeneralRe: Repost Pin
WebMaster31-May-08 7:15
WebMaster31-May-08 7:15 
AnswerRe: Aborting a method in c# Pin
Anthony Mushrow28-May-08 8:37
professionalAnthony Mushrow28-May-08 8:37 
GeneralRe: Aborting a method in c# Pin
WebMaster29-May-08 22:48
WebMaster29-May-08 22:48 
AnswerRe: Aborting a method in c# Pin
MarkB77728-May-08 12:28
MarkB77728-May-08 12:28 
QuestionDataGridView InvalidOperationException re-entrancy issue when setting its DataSource to null Pin
Cyrilix28-May-08 7:22
Cyrilix28-May-08 7:22 
AnswerRe: DataGridView InvalidOperationException re-entrancy issue when setting its DataSource to null Pin
leppie28-May-08 21:28
leppie28-May-08 21:28 

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.