Click here to Skip to main content
15,892,269 members
Home / Discussions / C#
   

C#

 
GeneralRe: Fastest way of filtering a DataTable?? Pin
Muammar©26-Feb-10 10:24
Muammar©26-Feb-10 10:24 
GeneralRe: Fastest way of filtering a DataTable?? Pin
Dave Kreskowiak26-Feb-10 12:43
mveDave Kreskowiak26-Feb-10 12:43 
QuestionSending mail from yahoo thru application Pin
Hum Dum26-Feb-10 0:26
Hum Dum26-Feb-10 0:26 
AnswerRe: Sending mail from yahoo thru application Pin
Bernhard Hiller26-Feb-10 2:22
Bernhard Hiller26-Feb-10 2:22 
QuestionGeneric List Pin
spankyleo12325-Feb-10 23:51
spankyleo12325-Feb-10 23:51 
AnswerRe: Generic List Pin
Pete O'Hanlon25-Feb-10 23:57
mvePete O'Hanlon25-Feb-10 23:57 
GeneralRe: Generic List [modified] Pin
spankyleo12326-Feb-10 0:12
spankyleo12326-Feb-10 0:12 
GeneralRe: Generic List Pin
Paulo Zemek26-Feb-10 1:47
mvaPaulo Zemek26-Feb-10 1:47 
If you don't know what is the blank value in advance, you can't do it the way you are trying.

You can, for example, add a "" (or string.Empty) in a list of strings, but this will not work for other types.

A possible solution is to create a generic "wrapper".
For example:
C#
public struct MyWrapper<T>
{
  public MyWrapper(T value)
  {
    _value = value;
    _hasValue = value != null;
  }

  private T _value;
  public T Value
  {
    get
    {
      return _value;
    }
  }
  
  private bool _hasValue;
  public bool HasValue
  {
    get
    {
      return _hasValue;
    }
  }

  public override string ToString()
  {
    if (!_hasValue)
      return "";

    return _value.ToString();
  }
}

As this wrapper is a struct, it can be initialized by the default constructor, in which case the _hasValue is false, so the ToString will return blank. If you initialize it with null (considering T is a reference type) it will do the same.

So, you can create a List<MyWrapper<T>> and add the first value as new MyWrapper<T> and then add a wrapper value for each value of the original list.
But, if the original list is changed, this list will not be.

*I didn't test the code, so maybe there is an error, but I think you can get the idea.

You can also go even further and create an IList wrapper over another IList. It is a big work, but:
You can always return Count as Count + 1.
When requested for item 0, you always return the empty wrapper value.
When requested for any other item, you return a wrapper over the real list item at (index-1) [after all, requesting item 1 means item 0 in the real list].

The advantage is that changing any item in the real data-source will be reflected in your wrapper data-source also, but it is a much more complex task.
GeneralRe: Generic List Pin
Pete O'Hanlon26-Feb-10 1:56
mvePete O'Hanlon26-Feb-10 1:56 
GeneralRe: Generic List Pin
Searril26-Feb-10 4:38
Searril26-Feb-10 4:38 
Question[SOLVED] I can't figure out EmitCalli of ILGenerator [modified] Pin
blackblizzard25-Feb-10 23:24
blackblizzard25-Feb-10 23:24 
AnswerRe: I can't figure out EmitCalli of ILGenerator Pin
Kythen26-Feb-10 13:08
Kythen26-Feb-10 13:08 
Question[SOLVED] How can I emit a call to a delegate whose type is unfinished at the time of the emit? [modified] Pin
blackblizzard28-Feb-10 6:28
blackblizzard28-Feb-10 6:28 
AnswerRe: How can I emit a call to a delegate whose type is unfinished at the time of the emit? Pin
blackblizzard4-Mar-10 21:23
blackblizzard4-Mar-10 21:23 
QuestionWebbrowser Control - selected Image Pin
hoernchenmeister25-Feb-10 21:25
hoernchenmeister25-Feb-10 21:25 
QuestionHow to Read a .doc in C# Pin
gouthami chintala25-Feb-10 20:48
gouthami chintala25-Feb-10 20:48 
AnswerMessage Removed Pin
25-Feb-10 20:50
stancrm25-Feb-10 20:50 
GeneralMessage Removed Pin
26-Feb-10 2:34
gouthami chintala26-Feb-10 2:34 
GeneralRe: How to Read a .doc in C# Pin
Dave Kreskowiak26-Feb-10 3:26
mveDave Kreskowiak26-Feb-10 3:26 
AnswerRe: How to Read a .doc in C# Pin
Mohammad Dayyan25-Feb-10 20:53
Mohammad Dayyan25-Feb-10 20:53 
AnswerRe: How to Read a .doc in C# Pin
Saksida Bojan25-Feb-10 21:03
Saksida Bojan25-Feb-10 21:03 
AnswerRe: How to Read a .doc in C# Pin
Kythen26-Feb-10 12:34
Kythen26-Feb-10 12:34 
QuestionCrystal Report XI issue Pin
Raza Hussain25-Feb-10 20:47
Raza Hussain25-Feb-10 20:47 
AnswerRe: Crystal Report XI issue Pin
Mohammad Dayyan25-Feb-10 20:57
Mohammad Dayyan25-Feb-10 20:57 
GeneralRe: Crystal Report XI issue Pin
Raza Hussain28-Feb-10 23:11
Raza Hussain28-Feb-10 23:11 

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.