使用的string.join显示的注意事项 [英] Showing Notes using String.Join
本文介绍了使用的string.join显示的注意事项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框,在其中用户可以把自己的笔记,然后我显示在同一页面右侧的音符。现在,在我的数据库我有列:
-Username结果
-Notes
< /块引用>
现在这里是代码中使用LINQ2SQL得到注意事项:
INT的getName = Int16.Parse(会话[选定]的ToString());
变种showNotes从em.Test
r其中r.Name ==的getName
选择r.Note =;
VAR showUser =从em.Test
r其中r.Name ==的getName
选择r.UserName;
tbShowNote.Text =的string.join(Environment.NewLine,showNotes);
tbShowNote.Text =的string.join(Environment.NewLine,showUser);
这一次让我看到用户名,但没有说明。我想说明是这样的:
- 这是一个测试注意事项。 -UserName1
块引用>
解决方案只要选择注释和用户名一个查询,然后做你的格式化算账:
VAR showNotes =从em.Test
,其中r.Nameř ==的getName
选择新的{名称= r.UserName,注意= r.Note}
VAR userNotes = showNotes.Select((X,I)=>的String.Format( {0} {1} - {2},
I,
x.Notes,
x.Name))。
tbShowNote.Text =的string.join(Environment.NewLine,userNotes);
I have a textbox in which users can put their notes and then I am showing those notes on the right hand side in the same page. Now in my DB I have columns:
-UserName
-NotesNow here is the code to get the notes using LINQ2SQL:
int getName = Int16.Parse(Session["Selected"].ToString()); var showNotes = from r in em.Test where r.Name == getName select r.Note; var showUser = from r in em.Test where r.Name == getName select r.UserName; tbShowNote.Text = String.Join(Environment.NewLine, showNotes); tbShowNote.Text = String.Join(Environment.NewLine, showUser);
This one shows me the UserName but not the Note. I want to show something like this:
- This is a Test Note. -UserName1
解决方案Just select notes and user name in one query, then do your formatting afterwards:
var showNotes = from r in em.Test where r.Name == getName select new { Name = r.UserName, Notes = r.Note } var userNotes = showNotes.Select((x,i) => string.Format("{0}. {1}-{2}", i, x.Notes, x.Name)); tbShowNote.Text = String.Join(Environment.NewLine, userNotes );
这篇关于使用的string.join显示的注意事项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文