Assuming InvoiceMaster
derives from or implements InvoiceHD
, and that you’re using C# 4 and .NET 4 or higher, you can just use generic variance:
return MstDtl.ToList<InvoiceHD>();
This uses the fact that an IEnumerable<InvoiceMaster>
is an IEnumerable<InvoiceHD>
because IEnumerable<T>
is covariant in T
.
Another way to solve it would be to change the declaration of MstDtl
to use explicit typing:
IEnumerable<InvoiceMaster> MstDtl = ...;
(I’d also suggest following regular C# naming, where local variables start with a lower-case letter, but that’s a different matter.)
Related Posts:
- Group by in LINQ
- Join/Where with LINQ and Lambda
- LINQ’s Distinct() on a particular property
- Sequence contains no elements?
- LEFT OUTER JOIN in LINQ
- ToList().ForEach in Linq
- Extension methods must be defined in a non-generic static class
- Proper Linq where clauses
- Extension methods must be defined in a non-generic static class
- Select distinct using linq
- Convert Linq Query Result to Dictionary
- Get single value from dictionary by key
- IEnumerable vs List – What to Use? How do they work?
- Sequence contains no matching element
- Linq select objects in list where exists IN (A,B,C)
- How do I concatenate two arrays in C#?
- Convert SQL to LINQ Query
- Sequence contains more than one element
- Quickest way to compare two generic lists for differences
- LINQ query on a DataTable
- Using .Select and .Where in a single LINQ statement
- Linq: GroupBy, Sum and Count
- How can I convert String to Int?
- CS0120: An object reference is required for the nonstatic field, method, or property ‘foo’
- How to find child of a GameObject or the script attached to child GameObject via script
- Process cannot access the file because it is being used by another proess
- How to convert JSON to XML or XML to JSON?
- Virustotal Trapmine suspicious.low.ml.score
- Convert int to string?
- Unity OnTriggerEnter2D not registering
- How to Sort a List
by a property in the object - The page was not displayed because the request entity is too large on IIS
- C# An established connection was aborted by the software in your host machine
- Multiple Inheritance in C#
- Return multiple values to a method caller
- Regex that accepts only numbers (0-9) and NO characters
- How to resolve this System.IO.FileNotFoundException
- Fire ontextchanged() event of an asp:TextBox via Javascript
- C# Gridview CheckBox Field VS (Template Field + CheckBox)
- Convert char to int in C#
- SmtpException: Unable to read data from the transport connection: net_io_connectionclosed
- The remote server returned an error: (403) Forbidden
- How can I get the application’s path in a .NET console application?
- How to add a delay for a 2 or 3 seconds
- Multiple file-extensions searchPattern for System.IO.Directory.GetFiles
- calling javascript function on OnClientClick event of a Submit button
- C# – Illegal characters in path
- Getting The ASCII Value of a character in a C# string
- Process exists with ExitCode 255
- The data types text and varchar are incompatible in the equal to operator in C#
- Name does not exist in the current context
- Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host
- Member ‘
‘ cannot be accessed with an instance reference - The remote server returned an error: (407) Proxy Authentication Required
- when do you need .ascx files and how would you use them?
- IsNumeric function in c#
- How to open a new form from another form
- C# – How to convert string to char?
- The calling thread must be STA, because many UI components require this in WPF
- Error when Building Project: Error building Player because scripts have compile errors in the editor
- Unity3D. Trying to send command for object without authority
- The type initializer for ‘MyClass’ threw an exception
- The server committed a protocol violation. Section=ResponseStatusLine ERROR
- Specified cast is not valid.. how to resolve this
- C# switch on type
- How to post JSON to a server using C#?
- C# Error (Cannot Implicitly convert type ‘string’ to ‘int’)
- .NET graph library around?
- EF CodeFirst: Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong
- Input string was not in a correct format
- How can I cast int to enum?
- What is the C# equivalent of friend?
- How to get relative path of a file in visual studio?
- Error Message: Type or namespace definition, or end-of-file expected
- Make first letter of a string upper case (with maximum performance)
- How can I wait for a thread to finish with .NET?
- How to add a new row to datagridview programmatically
- Unexpected character encountered while parsing value
- How do I exit a WPF application programmatically?
- OnCollisionEnter is not called in unity
- The name ‘ViewBag’ does not exist in the current context – Visual Studio 2015
- How to create a new object instance from a Type
- Cannot drop database because it is currently in use
- Troubleshooting “program does not contain a static ‘Main’ method” when it clearly does…?
- does not implement interface member
- Unity 5.2.2 changing Visual Studio back to MonoDevelop
- Differences between SFTP and “FTP over SSH”
- When should I use a List vs a LinkedList
- Remove punctuation from string with Regex
- Unity – How to stop Play Mode in case of infinite loop?
- Go To Definition: “Cannot navigate to the symbol under the caret.”
- Why am I getting an Exception with the message “Invalid setup on a non-virtual (overridable in VB) member…”?
- Is there a keyboard shortcut to maximize the Game window in Unity in Play Mode?
- IF Statement multiple conditions, same statement
- What is the easiest way to handle associative array in c#?
- What does the M stand for in C# Decimal literal notation?
- Iif equivalent in C#
- Convert an array to string
- is inaccessible due to its protection level
- Memory Leak caused by System.Drawing.Internal.GPStream