有人可以解释为什么以下程序内存不足吗?
class Program
{
private static void ThreadRoutine()
{
System.Windows.Media.MediaPlayer player = new System.Windows.Media.MediaPlayer();
}
static void Main(string[] args)
{
Thread aThread;
int iteration = 1;
while (true)
{
aThread = new Thread(ThreadRoutine);
aThread.Start();
aThread.Join();
Console.WriteLine("Iteration: " + iteration++);
}
}
}
Run Code Online (Sandbox Code Playgroud)
公平地说,我得到的具体例外是System.ComponentModel.Win32Exception"没有足够的存储空间来处理此命令".尝试创建新的MediaPlayer时会发生异常.
MediaPlayer没有实现IDisposable接口,所以我不确定是否还需要其他清理.我当然没有在MediaPlayer文档中找到任何内容.
我在接受采访时被要求对以下场景进行编码
电视有0-450个频道但是远程按钮2,5,8,9发生故障所以写一个程序来获取用户的输入并通过最短的路径遍历该频道
例:
47 - >无需遍历按钮4,7可用
45 - > 44 + 1输出来自哪个通道以及需要多少次遍历才能达到45.
55-> 55可以从47到达只有coz 54有5. ||| ly(50-55)其中有5个所以48和49分别有8和9.
我已经尝试了我的逻辑但是甚至无法以这样的方式编码它是所有输入的最佳最短路径请PLEASE帮助我使用逻辑或向我展示程序.
我正在阅读Google的示例代码,代码如下:
public class AttractionListFragment extends Fragment {
...
private class AttractionAdapter extends RecyclerView.Adapter<ViewHolder>
implements ItemClickListener {
public List<Attraction> mAttractionList;
private Context mContext;
public AttractionAdapter(Context context, List<Attraction> attractions) {
super();
mContext = context;
mAttractionList = attractions;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.d("TEST", "onCreateViewHolder");
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.list_row, parent, false);
return new ViewHolder(view, this);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Attraction attraction = mAttractionList.get(position);
holder.mTitleTextView.setText(attraction.name);
holder.mDescriptionTextView.setText(attraction.description);
Glide.with(mContext)
.load(attraction.imageUrl)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(R.drawable.empty_photo)
.override(mImageSize, …Run Code Online (Sandbox Code Playgroud) 假设我有100组3个值.第一个值是时间,第二个值是x位置,第三个值是y位置.例如,这将是一个超过100秒的点的xy位置.我有PHP背景.在PHP中,我会使用这样的3D关联数组:
position["time"]["x"]["y"]
Run Code Online (Sandbox Code Playgroud)
所以我可以在特定时间访问x,y值.你会如何在c#中做到这一点?我认为像列表和字典这样的泛型会做到这一点.但我不知道如何为3D数据集实现键值.
我正在使用任务工厂生成并行线程,我的代码如下.我有要求打印每个线程的完成时间,但不知道如何检查每个线程.目前我的代码正在等待所有任务完成,然后计算时间.
stp1.Start();
for (int i = 0; i < tsk.Length; i++)
{
tsk[i] = Task.Factory.StartNew((object obj) =>
{
resp = http.SynchronousRequest(web, 443, true, req);
}, i);
}
try
{
Task.WaitAll(tsk);
}
stp1.Stop();
Run Code Online (Sandbox Code Playgroud) 我正在尝试对List<string>包含每个数字后跟字母的元素列表的a 进行排序。这就是为什么每个元素不能简单地转换为 int 的原因。该列表在运行时生成,但例如,该列表可能包含以下元素:
10 dog, 53 cow, 2 crow, 29 horse, 12 rabbit, 107 frog, 35 cat, 7 dragon
Run Code Online (Sandbox Code Playgroud)
我试过这样排序:
public void Compare()
{
sortedList = sortedList.OrderBy(g => g).ToList();
}
Run Code Online (Sandbox Code Playgroud)
结果:
10 dog, 107 frog, 12 rabbit, 2 crow, 29 horse, 35 cat, 53 cow, 7 dragon
Run Code Online (Sandbox Code Playgroud)
很明显,它是按字母顺序排序的,因为在这个例子中,107 排在 12 之前,而 107 中的“10”小于 12。但我需要以某种方式对它进行排序,使其按照单词前面的数字顺序返回。
我需要这个例子来返回:
2 crow, 7 dragon, 10 dog, 12 rabbit, 29 horse, 35 cat, 53 cow, 107 frog
Run Code Online (Sandbox Code Playgroud)
我对编码很陌生,这让我完全难住了。关于如何达到我想要的结果的任何建议?
据我所知,接口无法实例化.
如果这是真的,为什么下面的代码编译和执行?它允许您创建可变接口.为什么这可能?
接口:
public interface IDynamicCode<out TCodeOut>
{
object DynamicClassInstance { get; set; }
TCodeOut Execute(string value = "");
}
Run Code Online (Sandbox Code Playgroud)
InCode:
var x = new IDynamicCode<string>[10];
Run Code Online (Sandbox Code Playgroud)
结果:

更新:
它只在声明数组时发生.不是一个例子.
我正在尝试保存对现有数据库条目的更新,但是当我这样做时,我收到错误:
附加类型为"FFInfo.DAL.Location"的实体失败,因为同一类型的另一个实体已具有相同的主键值.如果图中的任何实体具有冲突的键值,则在使用"附加"方法或将实体的状态设置为"未更改"或"已修改"时,可能会发生这种情况.这可能是因为某些实体是新的并且尚未收到数据库生成的键值.在这种情况下,使用"添加"方法或"已添加"实体状态来跟踪图形,然后根据需要将非新实体的状态设置为"未更改"或"已修改".
这是我的控制器代码.我正在使用的保存方法与我在其他几个方面使用的保存方法相同,可以毫无问题地更新数据.
[HttpPost, ValidateAntiForgeryToken]
public ActionResult EditLocation(AddEditLocationVM model, HttpPostedFileBase MapFile)
{
try
{
using (var db = new GeographyContext())
{
model.Sections = new SelectList(db.Sections.Where(s => s.ID > 1).OrderBy(s => s.Title), "ID", "Title").ToList();
model.GeographyTypes = new SelectList(db.GeographyTypes.Where(gt => gt.SectionID == model.Section).OrderBy(gt => gt.Name), "ID", "Name").ToList();
model.ParentLocations = new SelectList(db.Locations.Where(l => l.SectionID == model.Section).OrderBy(l => l.Name), "ID", "Name").ToList();
if (MapFile != null)
{
if (FileHelper.IsNotValidImage(MapFile))
{
ModelState.AddModelError("Invaalid File Type", "Images must be JPG, GIF, or PNG files.");
}
}
if (ModelState.IsValid) …Run Code Online (Sandbox Code Playgroud) 假设我有这个课程:
class Person {
public int ID;
public string Name;
}
Run Code Online (Sandbox Code Playgroud)
然后我有一份人员名单.
List<Person> persons = new List<Person>();
Run Code Online (Sandbox Code Playgroud)
其中充斥着很多随机的人.如何查询列表以获取ID最低的人?列表中的对象是随机顺序,因此ID最低的人可能不是第一个元素.我可以在不先排序列表的情况下实现此目的吗
我有一个类和一组属性名称定义如下:
public class Dog {
public string Name { get; set; }
public string Breed { get; set; }
public int Age { get; set; }
}
var desiredProperties = new [] {"Name", "Breed"};
Run Code Online (Sandbox Code Playgroud)
我还有一个返回dog对象列表的方法:
List<Dog> dogs = GetAllDogs();
Run Code Online (Sandbox Code Playgroud)
有没有办法可以返回dogs只包含desiredProperties数组中定义的属性的子集?最终,此结果列表将序列化为JSON.
考虑到允许用户指定任何属性组合(假设它们都是有效的)作为数组中的输出,我一直在努力解决这个问题.更多例子:
var desiredProperties = new [] {"Name", "Age"};
// Sample output, when serialized to JSON:
// [
// { Name: "Max", Age: 5 },
// { Name: "Spot", Age: 2 }
// ]
var desiredProperties = …Run Code Online (Sandbox Code Playgroud)