Most voted "c#" questions
This tag should be used when the question refers to some resource, information or problem related to the C#language. C# ("C Sharp") is a multi-paradigm programming language that has strongly typed variables, is imperative, declarative, functional, generic, object-oriented and component-oriented, which are designed to be executed in . NET Framework.
Learn more…13,899 questions
Sort by count of
-
3
votes2
answers252
viewsRead files twice
I have a project Asp.Net MVC in .Net Framework 4.0, with Entity Framework 5.0. I get multiple files in one method POST and I need to turn them into byte[] to save to Database (VARBINARY(MAX) - SQL…
c#asked 8 years, 3 months ago Jedaias Rodrigues 6,718 -
3
votes1
answer441
viewsGeneric Dbcontext Dbset Method with Entity Framework
I have an application in C# using Entity Framework. All of mine DbSet of DbContext, I extend them to have a default search for the grid, below example of the method. public static GridDTO…
-
3
votes2
answers122
viewsIs it correct in MVC to access data within the model?
In a C# MVC project, it is correct to access data within the model? For example: public class Cliente { public int Id { get; set; } public string Nome { get; set; } //outros atributos... public void…
-
3
votes2
answers445
viewsApp.Config Layered Project
Gentlemen, I have a layered application. In the business layer App.config I had to add the following code: <system.serviceModel> <bindings> <basicHttpBinding> <binding…
-
3
votes1
answer745
viewsInstantiate a class from its string name
I have a select where I have some options Teste1 Teste2 Teste3 I have a model for each option public class Teste1() { //atributos e métodos } I would like to receive this string ex in a certain part…
c#asked 6 years, 11 months ago Jhonatan Jorge de Lima 1,012 -
3
votes2
answers407
viewsSaving file path in Mysql
I’m having trouble saving file address in the database. When saving the address in the bank it is adding the amount of times I used the OpenFileDialog to save a file. Always save the address like…
-
3
votes3
answers56
viewsVisual Studio Variable View does not work
Good afternoon, you could help me, it’s been a while since my Visual Studio is like this I know I should be with a little arrow to visualize the object, this is very disturbing, I thank you already…
-
3
votes1
answer1975
viewsCalculate square root in C#
I have a calculator made in WPF C# with basic operations +,-,*,/, % . And now I wanted to try to improve my calculator. namespace calculadora { public delegate float? dlgoperacao(float? a, float?…
-
3
votes1
answer41
viewsProtect memory address
I’m developing a simple game. I want to protect the memory address where the player’s score is located so that only a specific process can access it, thus preventing the user from altering or…
-
3
votes1
answer85
viewsKeyboard shortcuts in Ribbonwindow
Hello, I’m developing an application using WPF and window based on Ribbonwindow of Ribboncontrolslibrary and I’m having problems with the Gesture of "Ctrl+0", only with the "Ctrl+Numpad0" I was able…
-
3
votes1
answer349
viewsHow Popular a Listview, and her Popular another Listview by Primary Key?
I have two Listviews that I need popular using LINQ to SQL (C#, WPF project) from a search field. When typing in the field(textbox) the Keydown event will popular the first Listview (1), as the…
-
3
votes3
answers823
viewsMethod that returns parent class to daughter class
I have the following classes: public class Pessoa { public int PessoaId { get; set; } public string Nome { get; set; } public DateTime DataNascimento { get; set; } } public class Cliente : Pessoa {…
-
3
votes2
answers114
viewsReturn original Textbox formatting
I have a method, which checks if a Textbox is filled, positive case follows normal, if it is blank, it displays a message on the screen, and paints Textbox background yellow, Here comes my doubt,…
-
3
votes1
answer235
viewsDotnetzip zipping file without folder directory
I am using dotnetzip to zip a file but the zip file takes the directory root of the file, wanted to zip only the file without the directories: public static void Zipar(FileInfo file) { using…
-
3
votes1
answer98
viewsReturning the values of a model dynamically in . NET MVC
I have an authentication class that stores the user ID in a session, which receives the model name corresponding to the current user, for example: users, admins, clients. Example:…
-
3
votes2
answers476
viewsDoubt Console.Readline
The user typed this in the console: adicionartempo;(qualquer número que ele digitou) string adicionartempo = Console.ReadLine(); After typing this, how can I get the number he typed and type in the…
c#asked 6 years, 11 months ago user92401 -
3
votes1
answer141
viewsWhat to test/implement in a viewmodel?
I am trying to implement a standard MVVM (Model - View - Viewmodel) that is related to MVP. Since Viewmodel, by my understanding, is responsible for "passing" the data from the View layer to the…
-
3
votes2
answers843
viewsOverwrite methods based on name only
I’m creating an abstract base class to provide a pattern for other classes. The base class methods shall be superscripted in the derived class. Now comes the cat jump. The superscript should happen…
-
3
votes1
answer1550
viewsConvert Char to string in C#
I’m trying to convert a char into string to use in split(), but it’s no use string path = HttpContext.Current.Request.Url.AbsolutePath; path = path.ToString(); string[] caminho = path.Split("/"); I…
c#asked 6 years, 10 months ago Marcos Brinner 1,282 -
3
votes3
answers149
viewsHow to generate new code from DBO
I have a table with the name Produtos in which I inserted 3 products for testing. Now I’m assembling the product registration form and I need to always generate a sequential product code from the…
-
3
votes1
answer623
viewsChange default printer c#
I am working on a solution where I need to change the default printer for a label printer to print and return to the previous standard printer. Would anyone have any solution to this?
-
3
votes1
answer258
views -
3
votes1
answer82
viewsIs it bad practice to cache an entire Model on IIS?
In an application I use sixteen times a code like var cliente = db.Clientes.Find(id); So that’s why I created a controller that returns me: [OutputCache(Duration = (10 * 60 * 60), VaryByParam =…
-
3
votes1
answer119
viewsHow to upload safely?
How to do upload/download of a file on an FTP server without this server’s login information being visible in the code? For example, I nay I want to do the following: string FTPhost =…
-
3
votes1
answer96
viewsHow to create variables in C# in the same way as in PHP?
You can use variable variables or something similar in C# as in PHP for example? $example = "etc.."; $var = "example"; // variáveis variáveis echo $$var; // etc... echo ${$var}; // etc... If not…
-
3
votes2
answers107
viewsHow to make this type of signature in C#?
It is possible to apply this signature type in C#? public class Teste { public void ver(Class<? extends Teste> tipo) { } } Like?
-
3
votes1
answer1032
viewsHow to upload and download the same request using Angularjs and Web api?
I am developing a functionality that will receive a spreadsheet in format . xlsx, will perform a processing and return this sheet with the columns added, in which case I should upload a file and in…
-
3
votes1
answer4415
viewsHow to reuse the Click of a button event in another method?
I have the event Click btnReabrirCaixa_Click and would like to reuse the process that has within that event in a method ValidarAberturaCaixa(), without copying and pasting the entire code, how could…
c#asked 6 years, 9 months ago Igor Carreiro 1,917 -
3
votes2
answers116
viewsIs that a Property, class attribute or what?
I have it in my code: public ICommand ChangePositionCommand => new Command((obj) => { _positionIndex++; if (_positionIndex >= Positions.Count) _positionIndex = 0; Position =…
-
3
votes2
answers985
viewsCreate a property for a bool variable that handles string and int
I am creating a project in which I search the database information, in this case it is a DBF file, and the field is of the Logical type. However, I want to create a property that can receive a…
-
3
votes3
answers455
viewsLINQ with JOIN and Where clause, how to do?
Good afternoon. I’m trying to make a left outer join (SQL) with LINQ, however, I’m not getting. The code of my class, is this one below. Can anyone give me a light on how I solve this? public class…
-
3
votes1
answer121
viewsHow to create a Bitmap larger than 9999 pixels
When trying a create a Bitmap I realized I can’t create with the size I wanted, I need an image with 16581375 x 1. Bitmap image = new Bitmap(16581375, 1); image.Save("Path aqui"); When I try to…
-
3
votes2
answers402
viewsSending information between PC (Windows Form, C#) and Android
I started to elaborate a project scheme, and as an idea I had to have several Androids devices sending data to a computer (I plan to do using Windows Form - C#, and maybe Xamarin for Mobile part). I…
-
3
votes2
answers165
viewsIf - Datatable condition
I need to compare a value of one of the fields of a DataTable, to fulfil a condition if, but I don’t know how to do it. follow below: public partial class imp_orcamento :…
-
3
votes2
answers410
viewsFactorial C# Calculator
I’m building a calculator in C# and I’m having a little problem constructing the button that calculates the factorial. private void btnfact_Click(object sender, RoutedEventArgs e) { primeiro +=…
c#asked 8 years, 2 months ago ChrisAdler 1 -
3
votes0
answers303
viewsPass the certificate password v
Good afternoon, I am developing a system where it uses certificate pfx, as it shows the code below I pass the directory where it is, but I cannot pass the password as parameter, the main object of…
c#asked 6 years, 9 months ago Matheus Antunes 31 -
3
votes1
answer803
viewsReplace a variable within a Word file
I am trying to do in C# (Windows Form application) print a Word .doc only that exchanging some vestments of the type @Nome by a string. In short, I have a contract and I need to print it. Stating…
-
3
votes2
answers1413
viewsHow to verify which is the name of the spreadsheet tab Excel C#
How to verify what is the name of the "Tab" (Sheet$) of the Excel spreadsheet before performing the import pro SQL ? My code so far: protected void btnProcessar_Click(object sender, EventArgs e) {…
-
3
votes2
answers4607
viewsHow to know which button was clicked?
I have three buttons, one for insert, another to alter and one for record. The button of record will work to save data either from an insertion or a change. How to identify which button I pressed to…
-
3
votes2
answers153
viewsKeyword for C# equivalent to Java’s "Synchronized"
Problem I am implementing a connection manager that implements the standard Singleton, managing a pool connections with unique keys for each new connection. So I’m having problems with the…
-
3
votes3
answers127
viewsMake a code that brings values like this(1K, 1M or 2G)
My rule is: If a figure is in the thousands, I must present so: 1564 = 1K 345,786 = 345K 2345 = 2K The same goes for millions and so on. Well, the question is how to get only the values before the…
-
3
votes2
answers131
viewsAPI does not receive list post
I have an API that receives a post, if I receive only a single contract, it receives the data normally: [HttpPost("GravaContratos")] public async Task<JsonResult> GravaContratos(ContratoModel…
-
3
votes6
answers6243
viewscheck repeated number inside the array c#
I created a predefined array with some numbers, and I want to know how many repeated numbers there are in the array. but it is only returning the size of the array and not Qtd of repeated numbers.…
c#asked 6 years, 8 months ago Cezar Mdlosci 85 -
3
votes1
answer3125
viewsWhy does calling a simple method in a class give a reference error?
I’m starting to study C# and I’m making the following mistake: CODE: CS0120 DESCRIPTION: An Object Reference is required for the non-static field, method, or Property…
-
3
votes1
answer62
viewsHow to view "Commandtext" with the added parameters?
MySqlCommand comm = new MySqlCommand("", conexao); comm.CommandText = ("SELECT @select FROM @from WHERE @where LIKE '@like'"); comm.Parameters.AddWithValue("@select", select);…
c#asked 6 years, 8 months ago Leonardo Bonetti 5,313 -
3
votes2
answers1752
viewsIs it possible to evaluate a ternary expression with 3 possible values?
Let’s say I have this account: var total = valor1 / valor2; The result could be three possible values, like: total > 5 total > 0 and total < 5 a positive value Note: They are percentage…
-
3
votes1
answer851
viewsPassing information to a Modal
I have this routine using the C#Razor. It lists my messages : Code: @for (int i = 0; i < 3; i++) { <div class="box-body" style="line-height:15px"> <ul class=" products-list…
-
3
votes1
answer792
viewsHow to set the size of an array of bytes dynamically?
I’m developing an application that creates a arquivo.txt and saved in a column of my table in the database. The problem is in the query of that file. What happens, when I want to do the query I have…
-
3
votes1
answer115
viewsHow do I know the client sent me something?
I made this code here following some tutorials over the internet. buttonAbrirConexão.Enabled = false; TcpListener servidor = new TcpListener(6554); servidor.Start(); while(true) {…
-
3
votes2
answers2261
viewsI need to do a SUM inside Group BY in Lambda
I’m trying to create a summary report where it consists of making a GROUP BY with SUM, i want to know how I could do it in c# with lambda or hql(Nhibernate), I managed to do a GROUP BY, but I can’t…