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

C#

 
AnswerRe: how to edit and delete lines from a text file Pin
jschell14-Aug-23 6:07
jschell14-Aug-23 6:07 
Questionthen the new student submits their answer to ... Pin
BillWoodruff8-Aug-23 4:23
professionalBillWoodruff8-Aug-23 4:23 
AnswerRe: then the new student submits their answer to ... Pin
Pete O'Hanlon8-Aug-23 19:33
mvePete O'Hanlon8-Aug-23 19:33 
GeneralRe: then the new student submits their answer to ... Pin
BillWoodruff10-Aug-23 0:36
professionalBillWoodruff10-Aug-23 0:36 
GeneralRe: then the new student submits their answer to ... Pin
Pete O'Hanlon10-Aug-23 3:29
mvePete O'Hanlon10-Aug-23 3:29 
GeneralRe: then the new student submits their answer to ... Pin
BillWoodruff10-Aug-23 2:09
professionalBillWoodruff10-Aug-23 2:09 
GeneralRe: then the new student submits their answer to ... Pin
Richard MacCutchan10-Aug-23 2:26
mveRichard MacCutchan10-Aug-23 2:26 
GeneralRe: then the new student submits their answer to ... Pin
Richard Deeming10-Aug-23 2:42
mveRichard Deeming10-Aug-23 2:42 
Just to make things more confusing, a static interface member with a default implementation must be marked as virtual, otherwise you'll get a compiler error when you try to use it:
C#
public interface IFoo
{
    static void S() => Console.WriteLine("Default");
}

static void Test<T>() where T : IFoo
{
    // CS0704 Cannot do non-virtual member lookup in 'T' because it is a type parameter
    T.S();
}
If you don't provide a default implementation, you have to mark it as abstract.

In order to provide its own implementation, a class has to declare the method as public, which doesn't match the interface declaration, leading to more confusion:
C#
public interface IFoo
{
    static virtual void S() => Console.WriteLine("Default");
}

public class Foo : IFoo
{
    // Why is this never called?
    static void S() => Console.WriteLine("Overridden");
}

static void Test<T>() where T : IFoo
{
    T.S();
}

Test<Foo>(); // Output: "Default"
You can alleviate that by marking the interface method as public:
C#
public interface IFoo
{
    public static virtual void S() => Console.WriteLine("Default");
}
But IMO, adding access modifiers to interface members goes against the "ethos" of interfaces. If I can see the interface, then I should be able to access all members of that interface, so they shouldn't need to be marked as public. And having some members protected or private just seems like nonsense!

And if that's still not confusing enough, the implementation of the static method cannot use the override modifier, even though it's required when you provide an implementation of a virtual / abstract method from a base class:
C#
public class Foo : IFoo
{
    // CS0112 A static member cannot be marked as 'override'
    public static override void StaticMethod() => Console.WriteLine("Overridden");
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: then the new student submits their answer to ... Pin
BillWoodruff10-Aug-23 12:38
professionalBillWoodruff10-Aug-23 12:38 
GeneralRe: then the new student submits their answer to ... Pin
Richard Deeming10-Aug-23 21:27
mveRichard Deeming10-Aug-23 21:27 
GeneralRe: then the new student submits their answer to ... Pin
Richard Deeming10-Aug-23 23:27
mveRichard Deeming10-Aug-23 23:27 
GeneralRe: then the new student submits their answer to ... Pin
Sandeep Mewara12-Aug-23 17:26
mveSandeep Mewara12-Aug-23 17:26 
QuestionCount DataGridview row values and compare with an Array (Resolved) Pin
Edilson Lemos 20217-Aug-23 14:21
Edilson Lemos 20217-Aug-23 14:21 
AnswerRe: Count DataGridview row values and compare with an Array Pin
OriginalGriff7-Aug-23 19:56
mveOriginalGriff7-Aug-23 19:56 
AnswerRe: Count DataGridview row values and compare with an Array Pin
Andre Oosthuizen7-Aug-23 22:46
mveAndre Oosthuizen7-Aug-23 22:46 
GeneralRe: Count DataGridview row values and compare with an Array Pin
Edilson Lemos 20219-Aug-23 14:00
Edilson Lemos 20219-Aug-23 14:00 
GeneralRe: Count DataGridview row values and compare with an Array Pin
Andre Oosthuizen9-Aug-23 21:24
mveAndre Oosthuizen9-Aug-23 21:24 
SuggestionRe: Count DataGridview row values and compare with an Array Pin
Richard Deeming9-Aug-23 21:51
mveRichard Deeming9-Aug-23 21:51 
GeneralRe: Count DataGridview row values and compare with an Array Pin
Edilson Lemos 202110-Aug-23 6:44
Edilson Lemos 202110-Aug-23 6:44 
AnswerRe: Count DataGridview row values and compare with an Array Pin
Edilson Lemos 202110-Aug-23 16:23
Edilson Lemos 202110-Aug-23 16:23 
GeneralRe: Count DataGridview row values and compare with an Array Pin
Andre Oosthuizen10-Aug-23 23:15
mveAndre Oosthuizen10-Aug-23 23:15 
QuestionSharepoint Pin
Kevin Marois7-Aug-23 8:15
professionalKevin Marois7-Aug-23 8:15 
AnswerRe: Sharepoint Pin
Andre Oosthuizen7-Aug-23 23:15
mveAndre Oosthuizen7-Aug-23 23:15 
GeneralRe: Sharepoint Pin
Kevin Marois8-Aug-23 12:22
professionalKevin Marois8-Aug-23 12:22 
GeneralRe: Sharepoint Pin
Andre Oosthuizen8-Aug-23 22:22
mveAndre Oosthuizen8-Aug-23 22:22 

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.