因此,我在Java中有一个递归方法来获取'n'的斐波纳契数 - 我唯一的问题是:时间复杂度是多少?我认为这是O(2 ^ n),但我可能会弄错?(我知道迭代更好,但这是一个练习)
public int fibonacciRecursive(int n)
{
if(n == 1 || n == 2) return 1;
else return fibonacciRecursive(n-2) + fibonacciRecursive(n-1);
}
Run Code Online (Sandbox Code Playgroud) 我正在使用C#和SQL Server 2005开发ASP .Net MVC 3应用程序.我还使用了Entity Framework和Code First Method.我有一个视图'索引',其中包含指向另一个视图'更新'的链接.在调试中,视图的值为NULL的问题.
该视图由名为ProfileGa的控制器填充.
这是控制器ProfileGa的一部分代码:
public ActionResult Update(string id)
{
FlowViewModel flv = db.FlowViewModels.Find(id);
return View(flv);
}
[HttpPost]
public ActionResult Update(FlowViewModel model)
{
Console.WriteLine("" + model.Nbr_Passage);
Gamme G = new Gamme();
ListG.Remove(G);
db.Gammes.Remove(G);
G.ID_Gamme = model.SelectedProfile_Ga;
G.ID_Poste = model.SelectedPoste;
G.Last_Posts = model.PostePrecedentSelected;
G.Next_Posts = model.PosteSuivantSelected;
G.Nbr_Passage = int.Parse(model.Nbr_Passage);
G.Position = int.Parse(model.Position);
ListG.Add(G);
db.Gammes.Add(G);
db.SaveChanges();
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
当我在线上放置一个断点时:
FlowViewModel flv = db.FlowViewModels.Find(id);
Run Code Online (Sandbox Code Playgroud)
flv的值为NULL.也许在数据库中没有指定id的记录.
我不能深入研究方法Find,因为这个方法的代码是预定义的(我没有写它).它是DbSet的一种方法.
相同的代码正在与其他视图一起使用,但仅限于此.
我认为问题取决于ID(ID_Gamme),它是DropDownList,不像其他人(TextBox).
这是视图索引的一部分代码,其中包含视图更新的链接:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.FlowViewModel>" %> …Run Code Online (Sandbox Code Playgroud) <td>
<asp:Label ID="TypeOfPaintingLabel" runat="server"
Text='<%# Eval("TypeOfPainting") %>' />
</td>
Run Code Online (Sandbox Code Playgroud)
有谁知道这是如何工作的?"NA"如果没有提供值,我想显示TypeOfPainting.
我创建了一个字典,它接受我的struct的值并存储它们.填写此内容如下:
_screenEntry.type = typeof(string);
_screenEntry.value = tagTextBox.Text;
_screen.nodeDictionary.Add("Tag ", _screenEntry);
Run Code Online (Sandbox Code Playgroud)
我的结构看起来像这样供参考:
public struct Entry
{
public Object value;
public Type type;
}
Run Code Online (Sandbox Code Playgroud)
但是,我现在正在尝试修改我第一次存储的值.我只是再次尝试重新调用nodeDictionary.Add,希望它会覆盖我以前的条目.但是,我收到一个错误,说我的字典已经有一个名为"Tag"的密钥,这是一个自我解释.
快速谷歌搜索让我发现,如果我想覆盖我的初始值,我只需要调用此行:
_screenTag = tagTextBox.Text;
_screen.nodeDictionary["Tag "] = _screenTag;
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
错误2无法将类型'string'隐式转换为'InMoTool.Entry'
我真的不知道如何转换它.有人可能会指出方向吗?
我有以下C#代码:
string File = "../images/main/profile-icon.png";
if (Request.ContentLength != 0)
{
int Size = Request.Files[0].ContentLength / 1024;
if (Size <= 512)
{
string LocalFile = Request.Files[0].FileName;
int dot = LocalFile.LastIndexOf('.');
string FileType = LocalFile.Substring(dot + 1);
if (FileType == "gif" || FileType == "jpg" || FileType == "png" || FileType == "GIF" || FileType == "JPG" || FileType == "PNG")
{
int LastIndex = LocalFile.LastIndexOf(@"\") + 1;
File = LocalFile.Substring(LastIndex, LocalFile.Length - LastIndex);
File = DateTime.Today.ToString();
string Path = Server.MapPath(" ../images/profiles") …Run Code Online (Sandbox Code Playgroud) <html>
<head>
<script>
function test(){
return function(){
alert("hi");
}
}
test();
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的代码,我可以问为什么它不能正常工作?
是否有可能创建一个我可以调用的函数,传递一个对象并让该函数返回任何数据类型.(我猜我必须告诉它要返回的数据类型,所以下面我刚刚传递了一个字符串 - 可能有一种更清洁的方式来处理这个)
public x GetValue(Object value, string datatype)
Run Code Online (Sandbox Code Playgroud)
我可以称这个传递: (DataRow["OrderID"], "Integer")
然后传递再次调用它:(DataRow["CustomerName"], "String")?
希望这是有道理的.
我正在使用:
string insertQ = "insert into Customer(Name, CNIC, Address, Balance) values(@name, @cnic, @address, @balance); SELECT CAST(scope_identity() AS int);";
SqlCommand insertCmd1 = new SqlCommand(insertQ, con);
Int32 newId = (Int32)insertCmd1.ExecuteScalar();
Run Code Online (Sandbox Code Playgroud)
但
"必须声明标量变量"
异常即将来临ExecuteScalar.
请告诉我如何解决它...
c# ×5
asp.net ×2
c#-4.0 ×1
dictionary ×1
eval ×1
fibonacci ×1
file ×1
file-upload ×1
function ×1
java ×1
javascript ×1
methods ×1
mysql ×1
recursion ×1
sql ×1
sql-server ×1
winforms ×1