i have create a class library (DLL) with many different methods. and the return different types of data(string string[] double double[]). Therefore i have created one class i called CustomDataType for all the methods containing different data types so each method in the Library can return object of the custom class and this way be able to return multiple data types I have done it like this:
public class CustomDataType
{
public double Value;
public string Timestamp;
public string Description;
public string Unit;
// special for GetparamterInfo
public string OpcItemUrl;
public string Source;
public double Gain;
public double Offset;
public string ParameterName;
public int ParameterID;
public double[] arrayOfValue;
public string[] arrayOfTimestamp;
//
public string[] arrayOfParameterName;
public string[] arrayOfUnit;
public string[] arrayOfDescription;
public int[] arrayOfParameterID;
public string[] arrayOfItemUrl;
public string[] arrayOfSource;
public string[] arrayOfModBusRegister;
public string[] arrayOfGain;
public string[] arrayOfOffset;
}
The Library contains methods like these:
public CustomDataType GetDeviceParameters(string deviceName)
{
......................
code
getDeviceParametersObj.arrayOfParameterName;
return getDeviceParametersObj;
}
public CustomDataType GetMaxMin(string parameterName, string period, string maxMin)
{
.....................................code
getMaxMingObj.Value = (double)reader["MaxMinValue"];
getMaxMingObj.Timestamp = reader["MeasurementDateTime"].ToString();
getMaxMingObj.Unit = reader["Unit"].ToString();
getMaxMingObj.Description = reader["Description"].ToString();
return getMaxMingObj;
}
public CustomDataType GetSelectedMaxMinData(string[] parameterName, string period, string mode)
{................................code
selectedMaxMinObj.arrayOfValue = MaxMinvalueList.ToArray();
selectedMaxMinObj.arrayOfTimestamp = MaxMintimeStampList.ToArray();
selectedMaxMinObj.arrayOfDescription = MaxMindescriptionList.ToArray();
selectedMaxMinObj.arrayOfUnit = MaxMinunitList.ToArray();
return selectedMaxMinObj;
}
As illustrated thi different methods returns different data types,and it works fine for me but when i import the DLL and want to use the methods Visual studio shwos all the data types in the CustomDataType class as suggestion for all the methods even though the return different data.This is illusrtated in the picture below. As we can see from the picture with the suggestion of all the different return data the user can get confused and choose wrong return data for some of the methods. So my question is how can i improve this. so Visual studio suggest just the belonging return data type for each method.

You’re taking a fundamentally wrong approach.
Make each method’s return type a type which includes the appropriate data. Some methods may have the same return type as each other; for other data types there may only be a single method which returns that type.
In some cases generics may help – for example, if you have different methods which return a “minimum and maximum value”, sometimes
long, sometimesint, sometimesfloator whatever, then you could have aMinMax<T>type.This should have given you the hint:
Given that the methods naturally “return different types of data” why would you give them all the same return type?
But putting everything into one data type is simply not the way forward. (It’s also extremely inefficient, but that’s a second order concern.)
Next step: get rid of those public fields, and use properties instead. You should consider whether it would make sense for some of your types to be immutable, and where you’re currently exposing arrays, expose read-only collections instead.