All Questions
3,849
questions
0
votes
1
answer
47
views
Parse a text file into instances of an object
I'm currently working on a university assignment, and I have a problem with parsing text files into instances of an object. A simple explanation of the program I'm working on is a takeaway shop loader....
-3
votes
0
answers
42
views
How could I filter out a text file to add instances of an object? [closed]
I'm currently doing an assignment where I create a takeaway shop. People can load their own text files that has menus for different takeaway shops, for example one text file has the menu for one ...
-1
votes
1
answer
60
views
Adding simple logic in C# objects that are meant for one-time use [duplicate]
This is not a "how-to" question, but rather a "share your thoughts" question for senor C# developers. I'm a junior C# developer who has worked in C# for about a year (and in other ...
2
votes
1
answer
53
views
Why is object array null later in the script even after confirming its not null after initialization
The title. there are no mentions of the spriterenderers or array anywhere else in the program
SpriteRenderer[,] Renderer = new SpriteRenderer[8,8];
void Awake()
{
if (D)
{
...
0
votes
1
answer
118
views
Refit - FromForm / Multipart method not working with request object
I have a .NET 8 web API controller with the following endpoint method in it :
[HttpPost()]
[Route("someRoute")]
[ProducesResponseType(typeof(SomeResponse), StatusCodes.Status200OK)]
public ...
1
vote
1
answer
70
views
Access nested objects in C#
I am trying to access specific properties from my object via Google Books API. The content is deserialized into two POCOs to access the nested object. I am stuck on is accessing the properties of ...
-1
votes
2
answers
79
views
Is there a way to make a class with no limit on the number of Generic Type Parameters in c#? [duplicate]
I am working on a project in which I need to define any number of possible parameters when creating an object.
public class base
{
//Variable Declarations here...
public base(){ //Handle ...
0
votes
0
answers
19
views
Model Creation for Dynamic property in C# [duplicate]
Existing data:
existing = {
"MediaLRN" :'2',
"Media":'a.2',
"CultureDetails":{
"24 Hrs": [
{
"Organism": "15&...
0
votes
2
answers
52
views
How to check that there are no duplicates in an array? [duplicate]
I'm writing an application in C# that prompts the user for data for objects of an Automobile class. One of the properties of the class for which the program prompts the user for data is ID number. If ...
1
vote
1
answer
67
views
== and Equals for Tuple<object>
i have a question why it works like this
var a = new Tuple<object, object, object>(1, 1, 1);
var b = new Tuple<object, object, object>(1, 1, 1);
Console.WriteLine(a.Item1==b.Item1);//...
-1
votes
3
answers
85
views
Reading object value from other class in C#
I always have coded in C++ but I am learning C# now. I got a trouble with accessing the object value.
Here is what I tried.
class Program
{
static void Main(string[] args)
{
...
1
vote
3
answers
122
views
Using the object value in the class in C# [closed]
I always have coded in C++, but now trying to learn C#. I was trying to create multiple objects and use data of them in C#. However, it does not work in the way I desire.
Here is the code I tried.
...
0
votes
0
answers
46
views
Is there a way to return data from a database call as an general object rather than a specified type, without creating a new class
I have a function that is trying to return a list of all transactions from the database. To do this it needs to retrieve all the data from TransactionItems, and then join that to the data retrieved ...
1
vote
2
answers
49
views
Why is null Unity Object equal to null in specialized class but not equal to null in generic class?
Attach TestMono to an empty GameObject, leave the serialized field uov empty and play. The result is not what I expected.
using System;
using UnityEngine;
using Object = UnityEngine.Object;
namespace ...
1
vote
1
answer
383
views
C# "Smart Reference"/"Handles" allowing for an object to be "destroyed" immediately
I am working on a small scale game engine and have reached a point where I would like to destroy a Game Object (destroy meaning all references to an object become null). This is important because even ...
0
votes
0
answers
33
views
Why is list of structs not IEnumerable<object>? [duplicate]
Running the below program gives the following output:
Class is object.
Class list is IEnumerable<object>.
Struct is object.
Struct list is not IEnumerable<object>.
That implies that a ...
1
vote
2
answers
167
views
C# Add List class to new List class without looping
I have a list of users returned in a class
My Class: List
public class EmployeeList
{
public int Emp_No { get; set; }
public string Sys_Prefix { get; set; }
public short Company_No { get; ...
0
votes
0
answers
69
views
Unity setactive() not working because of object name
So I have a sort of item system in my game and it opens a savefile to see what items the player has at the time, when it loads it enables and disables objects based on the savefile information. Which ...
-3
votes
1
answer
58
views
How to modify the object (textBox) that called the method from within the method itself?
EDIT: This question has been solved using "sender" (see answer below)--thank you to everyone who left comments!
I'm trying to create a method that I can call within any number of text fields ...
-1
votes
1
answer
48
views
In my C# project I get an string [,] type object as an output. When I want to print the output to console or file, the output is truncated. Why?
I have the method below, where I am subscribing to an OPC DA server items.
public void read_OPC_items(string ip)
{
using (var client = new EasyDAClient())
{
client.ItemChanged += ...
0
votes
1
answer
50
views
How can I convert (pass) an object that represents a two dimensional array to a 2-D array variable?
In my C# code I have an object in my code that represents a two dimensional array. I tried to write the value to a file by just converting it to string. I got something like an array but I saw the ...
1
vote
1
answer
26
views
C# Winforms: Recursive conversion from objet tree to TreeView duplicates entries
I'm trying to build a winforms TreeView from a tree of classes in C#, with the ability to select an item from the TreeView, by searching it's tag from the class structure.
I've been trying to ...
0
votes
1
answer
98
views
Return object property value inside a list, starting from a string
I have a list of objects where every object has a specific color.
That list is defined under a unique variable as well,
List<obj> listofobjs = new List<obj>();
What I'm trying to do is ...
0
votes
2
answers
154
views
Using LINQ, group list of object combination inside another list of objects
Update: Change class name as ComboProduct and Product for clear
public class Product
{
public string Name {get; set;}
}
public class ComboProduct
{
public int Id;
public List<Product&...
0
votes
1
answer
51
views
Retrieve one object from a list of objects, but not by index[], but by a name of a field [duplicate]
At the end you can find the classes and Json file.
How to retrieve one object from a list of objects, not by index[] but by a name of a field? I need to retrieve the full object.
After I deserialize a ...
0
votes
1
answer
52
views
How do I iterate through a list containing objects? c#
I created a list that stores objects from another class. The objects stored in my list each have a name and an integer. I want to know if I can iterate through my list and display the name of each ...
-1
votes
0
answers
35
views
Trouble with pickup physics in unity c# script
I am a beginner in unity scripting and I am having troubles with making a code on how to pick up an object.
I have ran through 4-5 YouTube tutorials and still cannot manage to pick up objects. When I ...
1
vote
1
answer
69
views
Access nested members in custom Settings-Class
I thought I had fully understood classes in C#, but atm I'm trying to create a custom Settings-Class for a Project of mine, but I just can't get it right.
What I want to achieve:
Have a class which ...
4
votes
2
answers
276
views
Difference between new() and new class() C#
What is the difference between new() and new class() because it seems that both run with no difference.
Human John = new();
or
Human John = new Human();
Let's say in this context it does not make ...
0
votes
0
answers
52
views
Creating object DLL(C#) in VBA
I've created dll and tlb file in C# to use it in VBA.
Code for dll looks like this:
using ModulPlanista.ServiceReference1;
using System;
using System.Collections.Generic;
using System.Linq;
namespace ...
0
votes
0
answers
91
views
Unity avoid hardcoding values?
In a click handler, I'm saving a reference to a ScriptableObject like so:
actionSO=itemScriptableObject.actions.action1;
I have several different actions attached to this gameObject:
...
0
votes
0
answers
18
views
System.NullReferenceException: 'Object reference not set to an instance of an object.' when trying to add Custom Object to Custom List [duplicate]
I am attempting to convert the price and product names from a json file into a C# usable format. for this I have written a customized json converter.
The Code goes as follows:
//using various stuff...
...
0
votes
0
answers
19
views
Index was out of range. Must be non-negative and less than the size of the collection. Error when adding objects to a list. C# Unity [duplicate]
I made a class particle in C# and am trying to call the constructor to create another object from that class inside the list lstParticles. I'm not sure why I can't add an object to the list even if ...
0
votes
2
answers
150
views
error CS0021: Cannot apply indexing with [] to an expression of type 'object'
My code:
foreach(var row in dt_test.Rows)
{
if (DateTime.ParseExact(row["TestDate"].ToString(),"dd.MM.yyyy",System.Globalization.CultureInfo.InvariantCulture) > DateTime....
0
votes
1
answer
88
views
How to reach the value of an object nested within an object?
I am somehow producing a C# object that contains another object structure. I am not sure how I can get hold of its content.
I have an array whose value is
{object[1,1]}
and type
object[,]
If I ...
0
votes
1
answer
373
views
How to make a method, that accepts an input, into a property of a class object?
The issue I've encountered here, is that I am currently trying to make an object that has a method as a property. I was able to get it to work on public static void methods, but not methods that ...
0
votes
3
answers
87
views
How to assign a property to a value depending on the value of a different property when returning a new object C#?
I have a project in C#. I have the following class:
public class MyClass
{
public int Id { get; set; }
public string Info { get; set; }
public string Name { get; set; }
}
Then, in one of ...
1
vote
1
answer
226
views
Unity "null" == Check Failing?
https://i.sstatic.net/jyYpi.gif
So I've been doing Unity C# programming for about 6 years now, and I only JUST found out about C# null v.s. Unity "null" (that's what you get when Unity is ...
0
votes
1
answer
25
views
C# Trying to use a method to assign attributes of an old object to new objects
I'm new to c# and programing in general, like a few weeks, and this has stumped me. The code below is the one I'm having trouble with.
internal class Program
{
static void Main(string[] ...
0
votes
1
answer
141
views
How to find out the size of an object recursively in c#?
I have a complex object with properties that range from int, double, string, List of objects, Dictionary<sting, dynamic> ,etc. How can I calculate the size of this object (without using GC) ?
I'...
1
vote
1
answer
240
views
How can I read the name of a thread in a C# application?
I'm working on a multithreaded application, written in C#.
I would like to verify if a thread is already running or not.
You might think "How easy can that be?", but there seems to be a ...
1
vote
1
answer
38
views
I am having an issue where I am unable to set objectA = objectB without getting all empty properties on objectA
I have tried several methods, 3 can be seen in the code below, the other was setting each property on the customer.ReconnectStats = to the corresponding property on the rs object. The fields on the rs ...
0
votes
1
answer
54
views
A property in Child Object in Parent Object-A is changed when a new property in Child Object in Parent Object-B is added
Consider this object
{
"ClassId": 101,
"Sections": [
{
"SectionId": 201,
"Subjects": [
{
...
-1
votes
1
answer
139
views
How do you access the properties of an object when that object is the value of a key/value pair in a dictionary in c#? [duplicate]
C#:
I have this dictionary:
Dictionary<string, Object> ourAnimals = new ();
Each key is a string, such as "d1".
Each value is an object. Here is the class definition for those objects:
...
0
votes
0
answers
481
views
'Find' is not allowed to be called from a MonoBehaviour constructor, call it in awake or start instead (but I did)
I'm getting the following error:
"UnityException: Find is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from ...
2
votes
2
answers
279
views
Getting all values of properties of an object into an array in c#
Im trying to get all the field values of an object into an array. but the problem is the fields of the object can have other types rather than string but ultimately all the values should be a string.
...
0
votes
3
answers
48
views
C# object list that can be declared, returning an iteration of items to be inserted into the main list
C# question.
I need to fill my main object property, that is a list of a custom object, but at some point, I need to add to this list a replication with a specific declaration, but I don't want to ...
1
vote
3
answers
70
views
Unable to cast to object
I had a code:
var result = BOBase.Search(Mapper.SourceBrowserType, searchCriteria);
var list = new List<IBO>(result.OfType<IBO>());
But I need to be able to add many elements in a list. I ...
0
votes
0
answers
333
views
how to pass object to test method in nunit in c#
How can I pass an object while testing with NUnit in c#
Hi
I have written some code and am trying to use NUnit Test. When I pass int or string it works but I dont know how to use this test method with ...
-2
votes
2
answers
103
views
Want to access dynamic property name from dynamic object
I have following JSON format.
{
"data": [
{
"id": 1,
"variants": [
{
"name": "Test",
...