本文整理汇总了C#中Object.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Object.ToString方法的具体用法?C# Object.ToString怎么用?C# Object.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object
的用法示例。
在下文中一共展示了Object.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getShortOf
protected string getShortOf(Object x)
{
if (x.ToString().Length < 10)
return x.ToString();
else
return x.ToString().Substring(0, 10);
}
示例2: CutString
/// <summary>
/// 截取字符串
/// </summary>
/// <param name="obj">字符串</param>
/// <param name="num">截取的长度</param>
/// <returns></returns>
public static string CutString(Object obj, int num)
{
if (obj == null)
return "";
if (obj.ToString().Length == 0)
return "";
if (obj.ToString().Length > num)
return obj.ToString().Substring(0, num) + "...";
else
return obj.ToString();
}
示例3: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Call Ctor with valid target reference and set trackResurrection to false");
try
{
Object obj = new Object();
WeakReference reference = new WeakReference(obj, false);
if ((reference.TrackResurrection != false) || (!reference.Target.Equals(obj)) )
{
TestLibrary.TestFramework.LogError("001.1", "Calling Ctor with valid target reference and set trackResurrection to false constructs wrong instance");
TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] reference.TrackResurrection = " + reference.TrackResurrection.ToString() +
", reference.Target = " + reference.Target.ToString() +
", obj = " + obj.ToString());
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例4: Format
protected String Format(Object obj)
{
if (obj is DateTime)
return ((DateTime)obj).ToString("dd-MM-yyyy");
return obj.ToString();
}
示例5: Validate
/// <summary>
/// This functon attempts to validiate a value.
/// </summary>
/// <param name="currentValue">
/// The current value to validate.
/// </param>
/// <param name="minValue">
/// The min valid value.
/// </param>
/// <param name="maxValue">
/// The max valid value.
/// </param>
/// <param name="defaultValue">
/// The default value to use if the current value is invalid.
/// </param>
/// <param name="obj">
/// The object whose data is being validated.
/// </param>
/// <param name="fieldName">
/// The name of the field being validated.
/// </param>
/// <param name="error">
/// Whether or not this is an error or warning if invalid.
/// </param>
/// <returns>
/// The new, validated value.
/// </returns>
public static int Validate(int currentValue, int minValue, int maxValue, int defaultValue, Object obj, string fieldName, bool error)
{
//check if the current value is out of the valid range
if (currentValue < minValue || currentValue > maxValue)
{
//construct the log message
string message = obj.ToString() +
" has its data \"" +
fieldName +
"\" out of its valid data range of " +
minValue +
" to " +
maxValue +
". Defaulting to " +
defaultValue +
".";
//display the log message
if (error)
Debug.LogError(message, obj);
else
Debug.LogWarning(message, obj);
//current value is invalid, return default value
return defaultValue;
}
//current value is valid, return current value
return currentValue;
}
示例6: Null2String
protected static String Null2String(Object _input)
{
if (_input == null)
{
return "";
}
return _input.ToString().Trim();
}
示例7:
public virtual int Compare
(
Object p_obj1
,Object p_obj2
)
{
return String.Compare( p_obj1.ToString() ,p_obj2.ToString() );
}
示例8: VratHodinu
public String VratHodinu(Object hodina, Object minuty)
{
String vrat;
String strMinuty=minuty.ToString();
if(strMinuty=="0") strMinuty="00";
vrat = hodina.ToString() + ":" + strMinuty;
return vrat;
}
示例9: getPositionName
protected string getPositionName(Object x)
{
int iPositionID = int.Parse(x.ToString());
String sPositionName = string.Empty;
PositionEntity oPos = new PositionEntity();
oPos = PositionBRL.GetOne(iPositionID);
if (oPos != null)
sPositionName = oPos.sName;
return sPositionName;
}
示例10: getStationaryIdArray
public static StationaryID[] getStationaryIdArray(Object idArray)
{
System.Diagnostics.Debug.WriteLine(" inside getStationaryIdArray");
string myString = idArray.ToString();
System.Diagnostics.Debug.WriteLine(" check json data::" + myString);
ArrayList idList = new ArrayList();
// var listOfId = new JavaScriptSerializer().Deserialize<List<StationaryID>>(idArray.ToString()).ToDictionary(x => x.Id);
StationaryID[] result = JsonConvert.DeserializeObject<StationaryID[]>(myString);
return result;
}
示例11: GetRootCategory
/// <summary>
/// Display the Category for a Category id
/// </summary>
/// <param name="CategoryID"></param>
/// <returns></returns>
public string GetRootCategory(Object CategoryID)
{
string path = "";
CategoryHelper _Categoryhelper = new CategoryHelper();
DataSet MyDataset= _Categoryhelper.GetCategoryHierarchy(ZNodeConfigManager.SiteConfig.PortalID);
foreach (DataRow dr in MyDataset.Tables[0].Rows)
{
if(dr["categoryid"].ToString() == CategoryID.ToString())
path += ProductHelper.GetCategoryPath(dr["Name"].ToString(), dr["Parent1CategoryName"].ToString(), dr["Parent2CategoryName"].ToString());
}
return path;
}
示例12: getPageType
public String getPageType(Object pageType)
{
int pageTypeId = int.Parse(pageType.ToString());
if (pageTypeId == 1) {
return "差旅费报销";
} else if (pageTypeId == 3) {
return "招待费报销";
} else if (pageTypeId == 4) {
return "日常费用报销";
} else {
return "";
}
}
示例13: getPageType
public String getPageType(Object pageType)
{
int pageTypeId = int.Parse(pageType.ToString());
if (pageTypeId == (int)SystemEnums.PageType.RebateApply) {
return "返利";
} else if (pageTypeId == (int)SystemEnums.PageType.GeneralApply) {
return "非价量相关";
} else if (pageTypeId == (int)SystemEnums.PageType.PromotionApply) {
return "价量相关";
} else {
return "";
}
}
示例14: Compare
public int Compare(Object object1, Object object2)
{
if (object1 == null) {
return 1;
}
if ((object1 is AIcmp) && (object2 is AIcmp)) {
Int32 i = Convert.ToInt32(object1.ToString());
Int32 j = Convert.ToInt32(object2.ToString());
if (j < i) return 1;
if (j > i) return -1;
return 0;
}
throw new ArgumentException ("Object must be of type AIcmp");
}
示例15: GetAllJobs
protected void GetAllJobs(object sender, EventArgs e)
{
Panel panel = sender as Panel;
DateTime now = System.DateTime.Now;
String daylabel = "";
DateTime daytime = new DateTime();
if (Session["Week"] == null)
{
Session.Add("Week", week);
}
sessionweekObject = Session["Week"];
if (sessionweekObject.ToString() == "0")
{
sessionweekObject = SiteUtilities.GetWeekNumber(DateTime.Now, 0);
}
List<JobList> jobLists = new List<JobList>();
GetDate(now, jobLists);
for (int i = 0; i < jobLists.Count; i++)
{
List<JobPersonList> personInJob = new List<JobPersonList>();
var tmplist = SiteUtilities.GetJobsByDate(jobLists[i].Date);
for (int j = 0; j < tmplist.Count; j++)
{
personInJob = SiteUtilities.GetJobPersonal(tmplist[j].JobId);
for (int k = 0; k < personInJob.Count; k++)
{
if (personInJob[k] != null)
{
string names = personInJob[k].Firstname + " " + personInJob[k].Lastname + " ";
tmplist[j].PersonsInThisJob += names;
}
}
}
jobLists[i].Jobs = tmplist;
}
jobRepeater.DataSource = jobLists;
jobRepeater.DataBind();
}