Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
-1 votes
1 answer
293 views

Creating a generic List with a variable number of objects

I'm trying to build a method that automatically fils a generic list. I've put together a method like this: public List<(object, object, object)> makeList<T1>(IEnumerable<T1> coll,...
another J.Doe 's user avatar
0 votes
3 answers
61 views

Change the same property of different objects without a common baseclass?

I found this thread: How to change the same properties of different objects in one method? But I have an additional requirement: I don't necessarily have a common baseclass for the objects: I wish to ...
Daniel's user avatar
  • 2,470
1 vote
0 answers
27 views

C# deep copy a generic Dictionary [duplicate]

I am making a copy of a Dictionary<string, object> using the Dictionary<TKey,TValue>(IDictionary<TKey,TValue>) constructor. However, I found that the object values within the ...
Mohamad Mustafa's user avatar
1 vote
2 answers
325 views

Loop through T or an Object when its passed a collection

I am writing a method that is passed an Object of any type. If it is passed a string, it will process this string. If it is passed a class it will process any strings within this class. If this class ...
Jay's user avatar
  • 900
0 votes
1 answer
340 views

C#, How to access object methods in a generic method

I have 2 data classes that have a method isSenior(). public class Staff : Member, IComparable<Staff>, IEquatable<Staff> { public string Occupation { get; set; } public override ...
MemeAddict's user avatar
1 vote
1 answer
37 views

How to reference a Property in a Generic Object using a For Loop in C#

I am trying to create a generic method for sorting a List of objects based on whatever property value was given. e.g. For a customer list I may want to sort by the customer name which is a string ...
user avatar
1 vote
2 answers
381 views

Apply one action to multiple objects C#

I have different objects: 6 buttons, Listbox, and 5 labels, those names are like lblHum, lblCo2... I need to show or hide them together with one button click. Is it possible (without putting objects ...
Afanasjewww's user avatar
0 votes
2 answers
76 views

searches a name from list of different types

I have tried below some logic, but I am looking for a more generic solution please help me out is there any other way to get the object. static class FinObj { public static ppl Find(List<ppl>...
AloneRaider's user avatar
-3 votes
2 answers
175 views

Pass a generic parameter through constructor [duplicate]

I have two classes, Companies and Contacts, I need to pass an instance of one of those classes through a Constructor of a form. private Address _address; private Object _genericObject; ...
Alex Martinez's user avatar
-2 votes
1 answer
365 views

C# Generic way to store unknown properties in List

I'd like to store LicenseInformations for multiple domains in my application. The structure looks the following way: public class LicenseData { // properties... public List<...
Andréw's user avatar
  • 106
0 votes
1 answer
44 views

In C#, if I have generic objects, how can I generically specify getting and setting fields on those objects?

I have two very similiar functions: public Dictionary<string, T> UpdateSuccessProperties<T, TU>(Dictionary<string, T> oldSObjectByAlternativeIds, List<TU> ...
Brian Kessler's user avatar
0 votes
0 answers
70 views

C# Passing a variable type to a generic method and casting the result object back to the type

I'm trying to wrap my head around how types and generic methods work with Newtonsoft.Json. I have the following example base class: public class Foo { public Type Expected; public object ...
3x071c's user avatar
  • 1,008
-1 votes
1 answer
402 views

C# Checking and calling object properties that may, or may not exist

Building a proof of concept, I've gotten most of it solved, this is just the final step of my proof of concept and I'm hitting a brick wall. I'm building an automatic constructor for a left nav on a ...
Taylor Haze's user avatar
1 vote
4 answers
972 views

The lists become empty when referenced from another class, where am i doing it wrong?

I have a class movie, where I have auto-implemented List 'Shows' to add Show class objects. I am able to add and access it in the main method, but when I call the list from another class named Access, ...
shaik sha vali's user avatar
1 vote
4 answers
224 views

Remove all null entries from generic list of Object

This one should be easy, but seems to be eluding me. Given this variable: (which contains ~30 records) var seriesData = new List<List<object>>(); How do I loop through every record, and ...
Penjimon's user avatar
  • 489

15 30 50 per page