© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
11 replies
Alex Frost

Help with Implicit Explicit operators

This is my operator definition
public static implicit operator EventViewModel(Entry e)
        {
            EventViewModel viewModel = new EventViewModel();
            viewModel.Id = e.Id;
            viewModel.Title = e.Title;
            viewModel.StartDate = e.DateStart;
            viewModel.EndDate = e.DateEnd;
            return viewModel;
        }
public static implicit operator EventViewModel(Entry e)
        {
            EventViewModel viewModel = new EventViewModel();
            viewModel.Id = e.Id;
            viewModel.Title = e.Title;
            viewModel.StartDate = e.DateStart;
            viewModel.EndDate = e.DateEnd;
            return viewModel;
        }

I've not been able to find the exacts. With this definition, will it convert from Entry to ViewModel or ViewModel to Entry? Because, with the said implementation, following conversion doesn't work:
EventData = Context.Entries.Where(e => e.UserId == UserId);
EventData = Context.Entries.Where(e => e.UserId == UserId);

The error is Can't convert from IQueryable<Entry> to IQueryable<ViewModel>
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Difference between explicit and implicit operators
C#CC# / help
2y ago
Struct with explicit layout
C#CC# / help
3y ago
Implicit insert
C#CC# / help
2y ago
Operators.ConcatenateObject()
C#CC# / help
4y ago