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

C#

 
GeneralRe: how to edit and delete lines from a text file Pin
Edilson Lemos 202113-Aug-23 11:15
Edilson Lemos 202113-Aug-23 11:15 
GeneralRe: how to edit and delete lines from a text file Pin
OriginalGriff13-Aug-23 19:08
mveOriginalGriff13-Aug-23 19:08 
AnswerRe: how to edit and delete lines from a text file Pin
Gerry Schmitz13-Aug-23 5:53
mveGerry Schmitz13-Aug-23 5:53 
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 
So, the biggest advantage of the interface implementation is that it allows you to add features to an interface without breaking existing implementations. Imagine that you have the following interface:
C#
public interface MyRestApi
{
  string ApiName { get; set; }
  int Version { get; set; }
  string RequestBody { get; set; }
}
Now, as an application API author, you have published this interface and your component uses it quite successfully; more importantly, you have shipped this out and 1/4 million happy customers are using your component and are supplying their own implementations of this API into your component. Let's say that you have decided that you want to upgrade your component and add a new feature to this interface; you have decided that it will support a check-sum. You don't want to upset those customers who are already using your component by breaking their build by adding a new property they have to supply. You don't want to stop those customers from having to change their code to use a version 2 of this API; which could be significant disruption. Finally, you want the customers to be able to use your upgraded capability, and adjust to supplying their own checksum implementation when they are ready. That's what this capability provides; you can upgrade the interface by supplying your own default implementation, satisfying the ability not to break things, and the consumer can upgrade the implementation if they want to later on. So, the next version of your component has this interface
C#
public interface MyRestApi
{
  string ApiName { get; set; }
  int Version { get; set; }
  string RequestBody { get; set; }
  uint Checksum() 
  {
    using CRC32 crc32 = new();
    byte[] data = Encoding.UTF8.GetBytes(RequestBody);
    byte[] hashBytes = crc32.ComputeHash(data);
    return BitConverter.ToUInt32(hashBytes, 0);
  }

}
Now, I've just typed this code into the text window here so it may not be 100% correct, but this is one of the reasons for this capability.


modified 10-Aug-23 9:53am.

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 
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 

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.