AdiZ
AdiZ
CC#
Created by AdiZ on 12/6/2023 in #help
✅ Declaring a Dictionary as a Member Variable
Trying to define a dictionary as a member variable in a class. Getting this error:
Array initializers can only be used in a variable or field initializer. Try using a new expression instead.
Can only use array initializer expressions to assign to array types. Try using a new expression instead.
Array initializers can only be used in a variable or field initializer. Try using a new expression instead.
Can only use array initializer expressions to assign to array types. Try using a new expression instead.
New to C# - what's happening here?
2 replies
CC#
Created by AdiZ on 12/3/2023 in #help
✅ Advent of Code Day 1 - Issue with Chars
For this problem, you essentially have to find the first and last digit contained in each line, so for a line 271lonepxp2flbmbz the first digit would be 2 and the last digit 2 as well. Put 'em together, you get 22. Now you have to find that value for each of the 1000 lines provided and add them all together.
string input = """
9sixsevenz3
seven1cvdvnhpgthfhfljmnq
6tvxlgrsevenjvbxbfqrsk4seven
9zml
""";

int sum = 0;
foreach(string word in input.Split())
{
List<int> nums = [];
foreach(char ch in word)
{
if(Char.IsDigit(ch))
{
nums.Add(Convert.ToInt32(ch - '0'));
}
}

int firstNumber = nums[0];
int lastNumber = nums[^1];
int fullNumber = firstNumber * 10 + lastNumber;
sum += fullNumber;
}

Console.WriteLine(sum);
string input = """
9sixsevenz3
seven1cvdvnhpgthfhfljmnq
6tvxlgrsevenjvbxbfqrsk4seven
9zml
""";

int sum = 0;
foreach(string word in input.Split())
{
List<int> nums = [];
foreach(char ch in word)
{
if(Char.IsDigit(ch))
{
nums.Add(Convert.ToInt32(ch - '0'));
}
}

int firstNumber = nums[0];
int lastNumber = nums[^1];
int fullNumber = firstNumber * 10 + lastNumber;
sum += fullNumber;
}

Console.WriteLine(sum);
This is my code. However, I just keep getting an Index Out of Range error on the line that says int firstNumber = nums[0]; and I just don't get why. I originally had the code a lot more condensed but I expanded it to debug and that appears to be where the issue is. Naturally I initially thought that nothing was being added to the array, but so far I can't figure out why that would be. I'm going to go and Console.WriteLine nums right now to see if it actually contains anything, but either way I'd appreciate it if someone could help me see what I did wrong here.
53 replies
CC#
Created by AdiZ on 11/23/2023 in #help
✅ Caesar Cipher Code Not Returning Anything
This is my code. I'm not understanding why, when I build this, nothing is outputted to the Console. Can anyone help?
27 replies
CC#
Created by AdiZ on 11/23/2023 in #help
✅ How to Fix Merge Conflicts? Beginner - Confused
No description
22 replies
CC#
Created by AdiZ on 11/22/2023 in #help
Absolute Beginner - Accessing Variables From Other Classes
Hi. DecodeButton.cs:
using UnityEngine;

public class DecodeButton : MonoBehaviour
{
void Start()
{
Decoders decoder = new Decoders();
}

void OnClick()
{
Decoders.CaesarCipher(ReadStringInput.input);
}
}
using UnityEngine;

public class DecodeButton : MonoBehaviour
{
void Start()
{
Decoders decoder = new Decoders();
}

void OnClick()
{
Decoders.CaesarCipher(ReadStringInput.input);
}
}
ReadStringInput.cs:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ReadStringInput : MonoBehaviour
{
public string input;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}

public void ReadInput(string s)
{
input = s;
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ReadStringInput : MonoBehaviour
{
public string input;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}

public void ReadInput(string s)
{
input = s;
}
}
In DecodeButton.cs, I'm getting the error CS0120 about Object references but frankly I'm not understanding it. Can someone help me out?
94 replies
CC#
Created by AdiZ on 11/22/2023 in #help
✅ Calculating Remaining Processing Time?
Let's say I'm running a bunch of loops and searching long arrays - essentially some task that will take, let's say, 10 seconds on average. How can I calculate the amount of time remaining to complete the calculation to show to the user of the app?
12 replies
CC#
Created by AdiZ on 11/20/2023 in #help
In VSCode, SDK not Recognized on ChromeOS
Hi. I just installed the .NET SDK and the Runtime by following the instructions for Ubuntu on the Microsoft Docs website. This is what I get when I run dotnet --info in the Linux terminal:
NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.6c33ef20

Runtime Environment:
OS Name: debian
OS Version: 11
OS Platform: Linux
RID: linux-x64
Base Path: /home/ztech58/.dotnet/sdk/8.0.100/

.NET workloads installed:
Workload version: 8.0.100-manifests.6c33ef20
There are no installed workloads to display.

Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71

.NET SDKs installed:
8.0.100 [/home/ztech58/.dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.0 [/home/ztech58/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.0 [/home/ztech58/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
DOTNET_ROOT [/home/ztech58/.dotnet]

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.6c33ef20

Runtime Environment:
OS Name: debian
OS Version: 11
OS Platform: Linux
RID: linux-x64
Base Path: /home/ztech58/.dotnet/sdk/8.0.100/

.NET workloads installed:
Workload version: 8.0.100-manifests.6c33ef20
There are no installed workloads to display.

Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71

.NET SDKs installed:
8.0.100 [/home/ztech58/.dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.0 [/home/ztech58/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.0 [/home/ztech58/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
DOTNET_ROOT [/home/ztech58/.dotnet]

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
And this is the error I get when I launch VSCode (or try to create a new C# project):
The .NET Core SDK cannot be located: Error running dotnet --info: Error: Command failed: dotnet --info
/bin/sh: 1: dotnet: not found


/bin/sh: 1: dotnet: not found
. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path.
The .NET Core SDK cannot be located: Error running dotnet --info: Error: Command failed: dotnet --info
/bin/sh: 1: dotnet: not found


/bin/sh: 1: dotnet: not found
. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path.
Does anyone know how to fix this?
7 replies
CC#
Created by AdiZ on 11/19/2023 in #help
✅ Quick - Unity "using" directive
Really quick question guys, when trying to use methods from other scripts in Unity, let's say the other script's name (and therefore the other script's class name) is Decoders, do I do using Decoders; or using static Decoders;?
8 replies
CC#
Created by AdiZ on 11/19/2023 in #help
✅ .Split() Returning Spaces Between Words in String[]
Hi. I have an string array string[] strArr of words in format [word1, word2] and so on - just a basic format.. I got that by performing .Split() on another string, let's say string x. x was in format
"""
word1
word2
"""
"""
word1
word2
"""
and so on, for 30,000 lines. Now that I've converted this all to an array, how can I print the array such that the Console output would be ["word1", "word2"] etc.? I want to initialize strArr instead of performing .Split() everytime my app starts.
91 replies
CC#
Created by AdiZ on 11/17/2023 in #help
✅ Visual Studio 2022 Failing to Create C# Project
No description
14 replies
CC#
Created by AdiZ on 11/16/2023 in #help
✅ Split Lines into Array Elements
I've got a list of common English words in the format
word1
word2
word3
word4
word1
word2
word3
word4
And so forth. How can I split this into an array of format `string[] arr = {"word1", "word2", "word3", "word4"}. I imagine this would be done with .Split() but it's not working for me.
26 replies
CC#
Created by AdiZ on 11/15/2023 in #help
✅ Foreach Loop Printing Multiple Chars from a String Simultaneously
string s = "Hello World";
foreach(char ch in s)
{
Console.WriteLine(ch);
}

string s = "Hello World";
foreach(char ch in s)
{
Console.WriteLine(ch);
}

Prints
He
l
l
o

W
o
r
l
d
He
l
l
o

W
o
r
l
d
Surely H and e shouldn't be printed on the same line? What am I misunderstanding here?
44 replies