Last active
April 6, 2016 15:27
-
-
Save uqmessias/c9684791b8e15ff69611ca74f54f4336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<object> TentaConverterListaDeStringParaObjeto(List<string> listaDeStrings) | |
{ | |
// Não vai compilar | |
return (List<object>)listaDeStrings; | |
} | |
public List<string> TentaConverterListaDeObjetoParaString(List<object> listaDeObjetos) | |
{ | |
// Não vai compilar | |
return (List<string>)listaDeObjetos; | |
} | |
public List<object> ConverteStringParaObjetos(List<string> listaDeStrings) | |
{ | |
// retorna todos os itens como object | |
return listaDeStrings.Cast<object>().ToList(); | |
} | |
public List<string> TentaConverterStringEmListaDeObjetos(List<object> listaDeObjetos) | |
{ | |
// Converte lista, se tiver algum iten que não é String, será lançado uma exceção (InvalidCastException) | |
return listaDeObjetos.Cast<string>().ToList(); | |
} | |
public List<string> FiltraStringEmListaDeObjetos(List<object> listaDeObjetos) | |
{ | |
// Retorna apenas os itens do tipo string, os outros serão ignorados | |
return listaDeObjetos.OfType<string>().ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment