我很确定这是重复的,但经过几个小时的搜索/尝试后,我一直无法找到解决方法.
我不是高级程序员,但我有相当数量的C++经验.我正在尝试学习C#并且在使用非常基本的语法方面遇到麻烦,特别是对于访问其他类.我一直在寻找简单的例子,而且绝大多数情况下,我发现的所有东西似乎都使用了一个巨大的类,其中使用了main方法,因此这些例子并没有太大帮助.
我想开发一个包含多个.cs文件(每个文件中有一个类)的解决方案,以及另一个包含我将用于测试的主要方法的.cs文件.我的解决方案名为DIVAT.我有一个Dealer.cs文件,其中包含以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DIVAT
{
public class Dealer
{
public List<Tuple<int, string>> deck;
Dealer()
{ // default constructor
Console.Out.WriteLine("Default constructor called. (Dealer class)");
string [] suitValue = {"c", "d", "h", "s"};
for(int i = 2; i <= 14; i++){
for(int j = 0; j <= 3; j++){
deck.Add(new Tuple<int, string>(i, suitValue[j]));
}
}
}
~Dealer()
{// destructor
Console.Out.WriteLine("Destrcutor called. (Dealer class)");
}
Tuple<int, string> Dealer.getCard(int cardNum)
{// getter
return deck[cardNum];
} …Run Code Online (Sandbox Code Playgroud) 我有以下脚本在chrome/Firefox中工作正常但在IE中没有.
对象不支持属性或方法'replace'
我需要替换部分网址并在新标签中打开该链接.基本上它运行在一个安全的站点后面,所有外部链接都在前面获取该服务器名称,所以我需要用'http:'替换它
$('a[href*="youtube.com"]').attr("href", $('a[href*="youtube.com"]').replace ("https://serverdomain.com/", "http:"))
Run Code Online (Sandbox Code Playgroud)
只有IE上面的脚本抛出错误.
我的模型类包含所需的查找值,这是一个基于查找的记录:
[Required]
[DisplayName("Business Unit")]
public string value { get; set; }
[Required] //not working on client side?
[DisplayName("Business Group")]
public int id_businessgroup { get; set; }
Run Code Online (Sandbox Code Playgroud)
视图:
<div class="editor-label">
@Html.LabelFor(model => model.value)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.value)
@Html.ValidationMessageFor(model => model.value)
</div>
<div class="editor-label">
@Html.LabelFor(x=>x.BusinessGroup.value)
</div>
<div class="editor-field">
@Html.DropDownListFor(x => x.id_businessgroup, new SelectList(ViewBag.BusinessGroups,"id","value"),"Please select group from list...")
@Html.ValidationMessageFor(x => x.id_businessgroup)
</div>
@section scripts{
@Html.Partial("ScriptUseChosen")
}
Run Code Online (Sandbox Code Playgroud)
控制器:
public ActionResult Create()
{
ViewBag.BusinessGroups = DB.BusinessGroups.Where(x => x.is_active).OrderBy(x => x.value).ToList();
return View();
} …Run Code Online (Sandbox Code Playgroud) validation asp.net-mvc client-side-validation html.dropdownlistfor jquery-chosen
我从客户端获取了一系列字符串.然后在我的webapi中,我将其拆分为以下内容
var splitId = string.Join(",", ids);
Run Code Online (Sandbox Code Playgroud)
然后我使用上面的变量我的Linq查询
这是我的Linq查询
var query = tableARepository.AsQueryable()
.Where(a=> splitId.Contains(a.Id.ToString()))
.Select(a => new {
Id = a.Id
, Name = a.Name
, FkId = tableBRepository.AsQueryable().Min(b => b.fkid=a.id)
});
Run Code Online (Sandbox Code Playgroud)
我得到这个例外:
LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式.","
这是因为包含.我该如何解决这个错误?
我正在用自己的类在c#中创建一个库dll.但是,对于算术运算(+, - ,*,/,...),我创建了类似.Add(c1,c2)的方法,其中c1和c2是我的类的对象.
这种方法很棒,但我更愿意说:c3 = c1 + c2; 因为我已经为我的类编写了我的Add函数,Multiply函数,Divide函数等,我想定义:
c1 = c2 + c3与:c1 = MyClass.Add(c2,c3);
如果可能的话,我会重用我的代码.我确信在网络上有关于所有这些的文档和信息,但我无法找到它,我搜索的任何内容,谷歌似乎都误解了我的问题.
如何为类的对象定义基本算术运算?
我正在尝试创建一个有点简单的InventoryTracker并且难以播种我的测试数据库.我目前正在尝试重置数据库并使用以下命令执行全新的代码优先迁移:
- update-database -targetmigration:"0" -force -verbose
- *Delete Current Migrations
- add-migration InitialCreate
- update-database
Run Code Online (Sandbox Code Playgroud)
当我运行update-database -targetmigration:"0" -force -verbose了Package Manager Console回报:The property 'Model_Id' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection<T> where T is a valid entity type.
这是我用我Model的名字INV_Models.cs Model或我忽略的东西的一个简单问题吗?目前,该应用程序已成功构建,但新迁移失败.
我的主要模式是INV_Assets具有[ForeignKey]值Manufacturers, …
我已经搜索过类似错误的答案,但一直找不到.此外,我知道如何修复错误(让所有公开 - 我真的不想做),但我真的不明白为什么这是不允许的.无论如何 - 我得到了
可访问性不一致:属性类型"E7XLibrary.Base.MultiSegmentBase"的可访问性低于属性"E7XLibrary.E7XGroupBase.GroupSegment"
我的MultiSegmentBase类被声明为内部类(SegmentBase类也是如此):
internal class MultiSegmentBase : SegmentBase
Run Code Online (Sandbox Code Playgroud)
我在我的公共E7XGroupBase类中使用MultiSegmentBase实例作为受保护的抽象属性:
public abstract class E7XGroupBase
{
internal abstract UInt64 Length { get; }
protected abstract MultiSegmentBase GroupSegment { get; }
internal virtual void Wrap(BinaryWriter writer)
{
GroupSegment.Length = this.Length;
GroupSegment.Wrap(writer);
}
}
Run Code Online (Sandbox Code Playgroud)
最后我有一个分离的公共类E7XSessionGroup类,它实现了抽象的E7XGroupBase,就像这样
public class E7XSessionGroup : E7XGroupBase
{
#region Properties
private SessionGroupSegment _groupSegment = null;
protected override MultiSegmentBase GroupSegment
{
get
{
if (_groupSegment == null)
_groupSegment = new SessionGroupSegment();
return _groupSegment;
}
}
Run Code Online (Sandbox Code Playgroud)
正如我所说的,我知道如果我只是将MultiSegmentBase声明为公共类而不是内部类,我就不会有这个错误,但是因为我正在创建一个API,所以我不想暴露MultiSegmentBase然后进一步展示所有类派生自MultiSegmentBase.
基本上,我的问题是为什么当我只在受保护的属性中使用MultiSegmentBase时,MultiSegmentBase需要像E7XGroupBase和E7XSessionGroup一样可访问?你们中的任何人都有一个很好的解决方法吗?
我正在尝试制作ajax请求来上传图片.我的问题是当我创建FormData时.我的控制台说"dataForm不是构造函数".
我怎么解决这个问题?
这是我的剧本
$("#new-broadcast-image-static").on("change", function(formData) {
var formData = new formData();
// line that console point the error //
var file = $("#new-broadcast-image-static")[0].files[0];
formData.set("image", file);
$.ajax({
url: apiUrl + "image/upload",
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
xhrFields: {
withCredentials: true
},
success: function(data) {
hashNewBroadcastImage = data.data.identifier;
$("#hash-new-broadcast-image-static").val(hashNewBroadcastImage);
}
});
});
Run Code Online (Sandbox Code Playgroud) 我正试图在导航到ViewModel时将服务注入.尽管我已经看过Brian Lagunas的博客,示例代码等,但有些东西似乎不对.
在我的App.cs中给出
public class App : PrismApplication
{
protected override void OnInitialized ()
{
NavigationService.NavigateAsync ("SignInPage", animated: false);
}
protected override void RegisterTypes ()
{
Container.RegisterTypeForNavigation<SignInPage>();
Container.RegisterType<IUserAuthentication, UserAuthenticationService>();
}
Run Code Online (Sandbox Code Playgroud)
}
注意:usingIUserAuthentication和UserAuthenticationService命名空间的语句已到位.
SignInPageViewModel.cs
private INavigationService _navigationService;
private IUserAuthentication _userAuthenticationService;
public SignInPageViewModel(INavigationService navigationService, IUserAuthentication userAuthenticationService)
{
_navigationService = navigationService;
_userAuthenticationService = userAuthenticationService;
}
Run Code Online (Sandbox Code Playgroud)
Container.RegisterType似乎不接受通用.我在Unity中看到的所有示例似乎都支持它,但是我收到以下错误.
The non-generic method 'IUnityContainer.RegisterType(Type, Type, string, LifetimeManager, params InjectionMember[])' cannot be used with type arguments
Run Code Online (Sandbox Code Playgroud)
这是一个构建错误.
包装信息
我在游戏中创建了一个键盘.我创建的游戏对象有10个按钮:0-9.玩家必须输入4位数代码才能打开门.一旦玩家输入第一个数字,它就会显示在键盘的屏幕上.
我已经完成了所有基本代码,但我确信我已经以非常低效的方式完成了这项工作.现在,我已将以下功能附加到我的一个键上,实际上是数字键1:
public void Key1() {
if (digit1entered == false) {
digit1 = 1;
displaycode.text = digit1.ToString () + digit2.ToString () + digit3.ToString () + digit4.ToString ();
print ("First digit entered");
digit1entered = true;
} else {
if (digit1entered == true && digit2entered == false) {
digit2 = 1;
digit2entered = true;
displaycode.text = digit1.ToString () + digit2.ToString () + digit3.ToString () + digit4.ToString ();
print ("2nd digit entered");
} else {
if (digit2entered == true && digit3entered == false) …Run Code Online (Sandbox Code Playgroud) c# ×7
class ×2
constructor ×2
javascript ×2
jquery ×2
ajax ×1
asp.net-mvc ×1
linq ×1
math ×1
methods ×1
prism ×1
validation ×1