yz
yz
CC#
Created by yz on 1/3/2024 in #help
C++ struct initializing in C#
in C++, we can do this -
struct Foo
{
int A;
int B;
};
Foo a = { 5, 7 };
std::cout << a.A; // 5
std::cout << a.B; // 7
struct Foo
{
int A;
int B;
};
Foo a = { 5, 7 };
std::cout << a.A; // 5
std::cout << a.B; // 7
But I found that I can't do this in C#. Do I have to assign values by each one like this?
a.A = 5;
a.B = 7;
a.A = 5;
a.B = 7;
I want to know how to assign member values simply in C#.
11 replies
CC#
Created by yz on 9/16/2023 in #help
❔ Problem with getting GPU info
I'm currently working on a console program that shows some information of user's PC for fun. I have a problem with getting GPU info, when user is using laptop. In my case, I have RTX on my laptop but the program only shows Intel UHD. How to get REAL GPU information? Not only the name of RTX, I am gonna need more information like temperatures, or etc. This is a part of my code.
internal class GPUInfo
{
public string Name { get; private set; }
public string DriverVersion { get; private set; }
public GPUInfo()
{
Name = string.Empty;
DriverVersion = string.Empty;
}
public void Update()
{
using (var searcher = new ManagementObjectSearcher("select * from Win32_VideoController"))
{
foreach (var obj in searcher.Get())
{
Name = obj["Name"] != null ? obj["Name"].ToString() : "Unknown";
DriverVersion = obj["DriverVersion"] != null ? obj["DriverVersion"].ToString() : "Unknown";
}
}
}
}
internal class GPUInfo
{
public string Name { get; private set; }
public string DriverVersion { get; private set; }
public GPUInfo()
{
Name = string.Empty;
DriverVersion = string.Empty;
}
public void Update()
{
using (var searcher = new ManagementObjectSearcher("select * from Win32_VideoController"))
{
foreach (var obj in searcher.Get())
{
Name = obj["Name"] != null ? obj["Name"].ToString() : "Unknown";
DriverVersion = obj["DriverVersion"] != null ? obj["DriverVersion"].ToString() : "Unknown";
}
}
}
}
8 replies