You must Sign In to post a response.
  • Category: WPF

    Why we declare class name as data type in C# as well as method return type as class name.

    why we declare class name as data type in C# as well as method return type as class name.

    e.g
    private TraceViewContainerModel cmTraceviewContainer;
    internal Device device;

    here TraceViewContainerModel and Device is class name.

    public TraceViewViewModel AddTraceObject(TraceObject trc, bool isNew)
    {
    bool useCurrentAxisSettings = false;
    ZedGraph.Scale xaxisScale = null;

    Again TraceViewViewModel this is class which is declare as return type in another class.
  • #769338
    Hi Ravi.

    It a object oriented programming language.
    If you are dealing with any string type functionality the the return type of your method should be string as below.

    public string SomeMethod()
    {
    string s="sridhar thota";
    return s;// am returning string i.e., "sridhar thota"
    }

    But if you are returning a object type i.e., fields more than two or three of a classlike below, then we have to use class name as return type.

    public class TraceViewViewModel
    {
    public int traceid {get;set;}
    public string tarcename {get;set;}
    }
    public TraceViewViewModel SomeMethod()
    {
    TraceViewViewModel obj=new TraceViewViewModel ();
    obj.traceid =1;
    obj.tarcename ="test";
    return obj;// am returning obj i.e., TraceViewViewModel object so we will declare return type method as class name.
    }

    Hope you got some idea.

    Sridhar Thota.
    Editor: DNS Forum.


  • Sign In to post your comments