OOC:出于好奇心
所以,作为一个小练习,为了学习,我决定检查我是否能够实现一个非常基本的递归函数,它将返回一个List<int>,但有以下限制:
1-结果应该由函数本身返回(而不是作为参数传递给void函数).
2 - 在函数体中声明没有本地"命名"变量.
我想出了下面的解决方案(BTW:这可以以任何方式改进吗?)
在这样做的过程中,我了解到这ToList()与投射不同List<T>(参见下面的示例) - 任何人都可以解释幕后发生的事情以及两者之间的区别是什么?
谢谢!
PS - 我正在使用4.0版(如果它很重要).
编辑:运行时错误是 Unable to cast object of type '<ConcatIterator>d__71'1[System.Int32]' to type 'System.Collections.Generic.List'1[System.Int32]'
public static List<int> SomeIntegers(int min, int max)
{
//assume max >= min for simplicity
if (min == max)
return new List<int>() { min };
// runtime error
//return (List<int>)(SomeIntegers(min, max - 1).Concat(new List<int>() { max }));
//works
return (SomeIntegers(min, max - 1).Concat(new List<int>() { max })).ToList();
}
Run Code Online (Sandbox Code Playgroud) 我对Java有所了解,但对Enterprise Java来说却是全新的.我正在尝试使用NetBeans 6.1和GlassFish Application Server.请引导我一些资源,告诉我实际上java企业应用程序是什么,它们与普通的java类不同.
哪个是最好的应用服务器(在Linux上)?
在我的Web应用程序中,我要继续审核用户操作.因此,每当用户执行操作时,我都会更新执行操作的对象,并保留该操作的审计跟踪.
现在如果我首先修改对象然后更新审计跟踪但审计跟踪失败那么什么?
显然我需要回滚修改对象的更改.我可以在简单的应用程序中使用Sql-Transactions,但我使用Subsonic与db通信.我怎么能处理这种情况?
我有一个关于单身人士的问题,我认为我知道答案......但每次情况弹出时我都会稍微猜测一下自己,所以我想知道具体的答案.
假设我有两个类设置如此...
public class ClassA
{
private static ClassA _classA;
public static ClassA Instance { get { return _classA ?? LoadClassA(); } }
private ClassA(){}
public static ClassA LoadClassA()
{
_classA = new ClassA();
return _classA;
}
private ClassB _classB = new ClassB();
public ClassB ClassB { get { return _classB; } set { _classB = value; } }
}
public class ClassB
{
}
Run Code Online (Sandbox Code Playgroud)
我的问题很简单.
我想知道如果我访问ClassA的单例,_classB字段是否也被视为静态?即使我没有将_classB声明为静态成员.
我总是基本上猜到_classB它被视为静态(一个内存位置),但我想知道肯定.我错了吗?每次从singleton ClassA访问时都会为_classB创建一个新对象...即使内存中只有一个ClassA?或者是因为我在声明上新建了_classB,导致只有一个实例?
提前谢谢,-Matt
我正在尝试运行ServiceStack示例项目.当我运行Web客户端时,我收到以下错误:
{System.BadImageFormatException: An attempt was made to load a program with an
incorrect format. (Exception from HRESULT: 0x8007000B)
at Mono.Data.Sqlite.UnsafeNativeMethods.sqlite3_open_v2(Byte[] utf8Filename,
IntPtr& db, Int32 flags, IntPtr vfs)
at Mono.Data.Sqlite.SQLite3.Open(String strFilename, SQLiteOpenFlagsEnum
flags, Int32 maxPoolSize, Boolean usePool)
at Mono.Data.Sqlite.SqliteConnection.Open()
at ServiceStack.OrmLite.OrmLiteConnection.Open()
at ServiceStack.OrmLite.OrmLiteConnectionFactory.OpenDbConnection()
at ServiceStack.Examples.ServiceInterface.Support.ConfigureDatabase
.Init(IDbConnectionFactory connectionFactory)
in E:\ServiceStack.Examples\src\ServiceStack.Examples\
ServiceStack.Examples.ServiceInterface\Support\ConfigureDatabase.cs:line 23}
Run Code Online (Sandbox Code Playgroud)
我已经下载了最新的System.Data.SQLite.dll文件并尝试使用它,但我仍然遇到同样的错误.我在Windows 7 64位盒子上运行64位VS2010.
我的一个朋友在开源软件中遇到了一个奇怪的问题OscarMcmaster.他让我帮忙,我能够解决造成问题的代码.以下是一种方法:
public BillingService getBillingCodeByCode(String code){
List list = billingServiceDao.findBillingCodesByCode( code,"BC");
if(list == null || list.size() ==0 ){
return null;
}
return (BillingService) list.get(0);
}
Run Code Online (Sandbox Code Playgroud)
将billingServiceDao被初始化Spring的容器:
private static BillingServiceDao billingServiceDao =
(BillingServiceDao) SpringUtils.getBean("billingServiceDao");
Run Code Online (Sandbox Code Playgroud)
在BillingServiceDao类中执行以下代码:
public List<BillingService> findBillingCodesByCode(String code, String region) {
Query query = entityManager.createQuery("select bs from....");
query.setParameter("code", code + "%");
query.setParameter("region", region);
@SuppressWarnings("unchecked")
List<BillingService> list = query.getResultList();
return list;
}
Run Code Online (Sandbox Code Playgroud)
罪魁祸首是query.getResultList();我来自其他宇宙(.Net)并且不知道问题的补救措施.
请帮我帮朋友解决这个问题.
编辑: - 堆栈跟踪
SEVERE: Servlet.service() for servlet action …Run Code Online (Sandbox Code Playgroud) 所以继承我的问题.我设置了一个按钮,当点击它应该打开一个新的活动但是当它被点击时我收到一个错误:不幸的是"app_name"已经停止工作我的logcat说:致命异常主要
所以继承我的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="58dp"
android:text="Monday"
android:textSize="20sp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="30dp"
android:textSize="20sp"
android:text="Tuesday" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="30dp"
android:textSize="20sp"
android:text="Wednesday" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:layout_marginTop="30dp"
android:textSize="20sp"
android:text="Thursday" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_below="@+id/textView4"
android:layout_marginTop="30dp"
android:textSize="20sp"
android:text="Friday" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView5"
android:layout_below="@+id/textView5"
android:layout_marginTop="30dp"
android:textSize="20sp"
android:text="Saturday" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView6"
android:layout_below="@+id/textView6"
android:layout_marginTop="30dp"
android:textSize="20sp"
android:text="Sunday" />
<Button …Run Code Online (Sandbox Code Playgroud) 我在Visual Studion 2013 Express for Web中使用ASP.Net MVC模板创建了一个简单的项目.它不使用任何身份验证.然后我安装了EntityFramework(v6.0.1)EntityFramework.SqlServerCompact包.
我的DbContext类非常简单:
public class EditTestContext : DbContext
{
public EditTestContext() : base("EditTestContext")
{
}
public EditTestContext(string connectionString) : base(connectionString)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer(
new DropCreateDatabaseIfModelChanges<EditTestContext>());
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Configurations.Add(new EditTestConfig());
}
}
Run Code Online (Sandbox Code Playgroud)
实际的上下文对象是在Unit of Work类中创建的:
public class EditTestUoW:IEditTestUoW,IDisposable
{
private DbContext dbContext;
public EditTestUoW()
{
CreateDbContext();
}
private void CreateDbContext()
{
dbContext = new EditTestContext();//NEW DBCONTEXT OBJECT IS CREATED
dbContext.Configuration.LazyLoadingEnabled = false;
dbContext.Configuration.ProxyCreationEnabled = false;
dbContext.Configuration.ValidateOnSaveEnabled = …Run Code Online (Sandbox Code Playgroud) 我有一个包含asp:Literal的用户控件.
<div>
<asp:Literal id="MenuContainer" runat="server" />
</div>
Run Code Online (Sandbox Code Playgroud)
代码隐藏页面中有一个初始化控件的方法:
internal void Setup(MyBusinessObject obj)
{
MenuObject menu = MenuHelper.GetMenu(obj.State);
if(obj == null)
MenuContainer.Visible = false;
//other code
}
Run Code Online (Sandbox Code Playgroud)
在使用控件的页面中,我在LoadComplete事件处理程序中调用控件的Setup方法(我在Load事件中首先调用它).无论MyBusinessObject为null还是非null,当我在用户控件上访问Literal时,我都会收到错误:
Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)
是什么原因以及对此有何补救措施?
假设我在类中有一个数组或任何其他集合,以及一个返回它的属性,如下所示:
public class Foo
{
public IList<Bar> Bars{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
现在,我可以这样写:
public Bar Bar[int index]
{
get
{
//usual null and length check on Bars omitted for calarity
return Bars[index];
}
}
Run Code Online (Sandbox Code Playgroud) c# ×5
asp.net ×2
android ×1
button ×1
casting ×1
collections ×1
dbcontext ×1
hibernate ×1
java ×1
java-ee ×1
onclick ×1
properties ×1
servicestack ×1
singleton ×1
spring ×1
sqlite ×1
static ×1
subsonic ×1
transactions ×1