Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void DepartmentName_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            try
            {
                ((ITransaction)AppVariables.automator.AccountObj).DepartmentID = WebFormHelper.GetAccountIDFromName(DepartmentName.Text, AccountType.departmentMaster);
                ((ITransaction)AppVariables.automator.AccountObj).DepartmentName = DepartmentName.Text;
            }



In above code i didnt get why we have taken (ITransaction),what it called/means(return type or anything else)??
as i have declared properties as DepartmentID and DepartmentName in interface ITransaction and implemented it in Class Transaction.

also, can we take Transaction instead of ITransaction in above snippet? i tried this, it works for me but , didnt get what will be correct there(ITransaction or Transaction).
Posted

1 solution

(ITransaction) is a cast - it is converting whatever the AccountObj object is into an instance of an object implementing (ITransaction) without any other gubbins the original object class may derive from. Without knowing what AccountObj can return, it is difficult to explain more.

"can we take Transaction instead of ITransaction in above snippet?"

No idea. Since we have no idea what AccountObj returns, much less the relationship between Transaction and ITransaction we can't have a clue!
 
Share this answer
 
Comments
durgeshtupkar10 23-Aug-12 5:09am    
as name indicates it returns integer and string respectively.
for more here is some ,


Interface ITransaction:----

///
/// The DepartmentID
///

int DepartmentID { get; set; }


///
/// The DepartmentName
///

string DepartmentName { get; set; }



And class Transaction:----


public class Transaction : ITransaction

private int departmentID;
///
/// The Department
///

public int DepartmentID
{
get { return this.departmentID; }
set { this.departmentID = value; }
}

private string departmentName;
///
/// The DepartmentName
///

public string DepartmentName
{
get { return this.departmentName; }
set { this.departmentName = value; }
}


this.departmentID = 0;
this.departmentName = string.Empty;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900