我在这段代码中使用TransactionScope:
private void ExecuteSP()
{
bool IsComplete = false;
SqlCommand sqlComm = null;
//6 hours!!!
TimeSpan ts1 = new TimeSpan(6, 0, 0);
try
{
using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew, ts1))
{
using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
{
//open sql connection
sqlConn.Open();
try
{
//create new sqlCommand
sqlComm = new SqlCommand();
for (int i = 1; i <= 2; i++)
{
IsComplete = true;
//This command takes 15 minutes
sqlComm.CommandText = "exec TestSp";
sqlComm.Connection = sqlConn;
sqlComm.CommandType = CommandType.Text; …Run Code Online (Sandbox Code Playgroud) 如果我想将Enumerable(IEnumerable<T>)转换为列表.
什么更有效:
myEnumerable.ToList()
要么 new List<T>(myEnumerable)
谢谢!
我有窗口,其中DataContext绑定到ViewModel对象(示例为VM1).VM1有很多属性,其中一个是名为"MyTitle"的字符串.
我在'Window\Grid\DataGrid'中有一个DataGridTextColumn.如何将DataGridTextColumn中的属性"Header"绑定到VM1 ViewModel中的属性"MyTitle"?
谢谢!
我想创建一个具有动态视图的区域(一个区域中有多个视图).需要通过ComboBox选择事件更改区域内容(comobox项目是视图实例).我希望ComboBox中的更改将通过所选视图项更改区域中的视图.
我的问题是什么区别:
MyView view= new MyView();
IRegion region = new Region();
region.Name="MyRegion";
regionManager.Regions.Add(region);
region.Add(view);
region.Activate(view);
Run Code Online (Sandbox Code Playgroud)
至:
regionManager.RegisterViewWithRegion("MyRegion",type(MyView));
Run Code Online (Sandbox Code Playgroud)
?
使用动态区域的最佳方式是什么?
我使用一个有2个视图的区域.我有一个ComboBox允许用户选择区域中的视图.
我有两个问题:
第一个问题是:有什么区别:
_regionManager.Regions.Add("MyRegion")
_regionManager.Regions["MyRegion"].Add(container.Resolve<OneView>())
_regionManager.Regions["MyRegion"].Add(container.Resolve<SecondView>())
Run Code Online (Sandbox Code Playgroud)
至:
_regionManager.RegisterViewWithRegion("MyRegion", () => container.Resolve<OneView>());
_regionManager.RegisterViewWithRegion("MyRegion", () => container.Resolve<SecondView>());
Run Code Online (Sandbox Code Playgroud)
我的第二个问题是:有什么区别:
_regionManager.Regions["MyRegion"].ActiveViews.ForEach(view => _region.Deactivate(view));
_regionManager.Regions["MyRegion"].Activate(container.Resolve<SecondView>());
Run Code Online (Sandbox Code Playgroud)
至:
_regionManager.Regions["MyRegion"].RequestNavigate(new Uri("SecondView", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我有一个具有x和y值的A类列表:
class A
{
public int X { get; set; }
public int Y { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的列表:
List<A> MyList = GetListOfA();
Run Code Online (Sandbox Code Playgroud)
我想通过计算A属性的值来对列表进行排序.例如今天美元汇率乘以X.如果我将使用OrderBy表达式,该方法将计算x*log(x)次.
我找到了一些方法来创建内部类,包括值和变量,匿名类型列表,将包括变量和计算值的列表,通过计算值的键将其添加到排序字典等.
使用简洁明了的语法来实现它的最佳方法是什么?
我在.Net framework 4中使用WPF.
我创建了一个背景颜色为X的按钮.
我为按钮创建了一个样式,在IsMouseOver上启动ColorAnimation,将背景颜色更改为蓝色.
如果IsMouseOver为假(鼠标在按钮上没有记录器),我想将按钮背景恢复为颜色X.
示例代码:
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Duration="0:0:0.5" Storyboard.TargetName="MyButton" Storyboard.TargetProperty="Fill.Color" To="Blue"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我想在类型和该类型的实例之间创建一个字典.
例如,字典MyTypeDictionary:
Dictionary<Type,InstanceOfType> MyTypeDictionary = new Dictionary<Type,InstanceOfType>();
MyTypeDictionary.Add(typeof(int),4);
MyTypeDictionary.Add(typeof(string),"hello world");
MyTypeDictionary.Add(typeof(DateTime),Datetime.Now);
int MyInt = MyTypeDictionary[typeof(int)];
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
如何获取特定类型中使用的所有类型?
类“MyClass”的示例:
[MyAttribute(new OtherType(TestEnum.EnumValue1))]
public class MyClass:MyOtherClass
{
public Type MyType { get; set; }
public string MyString { get; set; }
private DateTime MyDateTime;
[OtherAttribute()]
public int MyMethod(double doubleNumber, float floatNumber)
{
justMyClass myJustClass = new justMyClass();
return (int)doubleNumber / (int)floatNumber + myJustClass.Count();
}
}
Run Code Online (Sandbox Code Playgroud)
我想获取类型:MyAttribute、OtherType、TestEnum、MyClass、MyOtherClass、Type、string、DateTime、OtherAttribute、int、double、float 和 justMyClass。
有什么办法可以做到吗?
c# ×8
wpf ×4
mvvm ×3
.net ×2
collections ×2
prism ×2
app-config ×1
datacontext ×1
datagrid ×1
dictionary ×1
ienumerable ×1
lambda ×1
linq ×1
list ×1
reflection ×1
region ×1
regions ×1
sorting ×1
sql ×1
styles ×1
types ×1