|
I'm using parallel arrays to display names and grades of students. I am stuck at displaying the arrays. I get System.String[] instead of the input value I want. This is my code what am I doing wrong:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Parrallel_Arrays {
public partial class frmGrades : Form {
String nameString = "Aaron Ben Carmelina Dorethy Erinn Karin " +
"Lester Mitsue Nichol Ria Sherie Zachary";
String assignmentsString = "44 92 100 100 100 97 100 95 100 0 100 100 " +
"95 95 97 90 100 95 100 100 100 100 100 75 " +
"98 100 65 0 100 100 100 100 100 100 95 75 " +
"85 100 0 50 100 95 90 0 80 100 100 100";
String[] arrayNames = new String[12];
String[,] arrayGrades = new String[4, 12];
String[] arrayAverage = new String[12];
public frmGrades() {
InitializeComponent();
}
private void frmGrades_Load(object sender, EventArgs e) {
}
//Method to Fill Array
private void FillArray(String[] name, String[,] grade) {
String[] arrayNames = { nameString };
String[,] arrayGrades = { { assignmentsString } };
String[] arrayAverage = { };
char[] separator = new char[] { ' ' };
String[] tokens = assignmentsString.Split(separator);
String[] token2 = nameString.Split(separator);
foreach (String token in tokens) ;
}
//Method to Display Array of names and assignment grades
private void DisplayArray(String[] nameString, String[,] assignmentsString) {
for (int i = 0; i < nameString.Length; i++) {
lbxDisplay.Items.Add(nameString[i] + " ");
}
}
|
|
|
|
|
String[] arrayNames = { nameString };
You cannot assign a string to an array like that. You must create the array first, or use String.Split [^] to separate the individual fields.
|
|
|
|
|
Just to back up what Pete Richard says, this code:
String[] arrayNames = { nameString }; Doesn't do what you think.
When you use this construct:
string[] x = {...} You are telling the system that each item inside the "{" and "}" is to be treated as a single string - so if it isn't a string already, the system will apply an implicit conversion:
String[] arrayNames = { nameString.ToString() }; Since nameString is an array and the Array class doesn't provide an explicit ToString override, the default object ToString implementation is used instead, which returns the name of the class instead of the content: "System.String[]"
As Pete says, use Split instead:
String[] arrayNames = nameString.Split(' ');
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 7-Nov-16 6:51am.
|
|
|
|
|
OriginalGriff wrote: what Pete says Who he?
|
|
|
|
|
You want accuracy on a Monday morning?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I am working on datagridview control in c# . I have three columns and I want to add the values from the first and second columns to get the value on the third column
|
|
|
|
|
|
Hi guys,
I've been struggling with a list inside a list. I have a table "cart_product" that contains 2 columns: cart_id and product_id.
Also I have a product table "product" with al the information of a product ( name, product_id, price etc ). I want to get the product information when I read the cart from the website, so I can show the price, name etc.
The problem I have is that I can't combine the 2 classes that I've made. If I use them separate its works correctly but combining them wont work..
public void Fetch()
{
database.Query("SELECT * FROM ws_cart_product WHERE cart_id=?cart_id;");
database.Add("?cart_id", cart_id);
foreach (DataRow row in database.FetchAsDataTable().Rows)
{
cart_id = global.ParseInt(row["cart_id"].ToString());
if (row["product_id"] != DBNull.Value)
{
product_id = global.ParseInt(row["product_id"].ToString());
}
if (row["parent_id"] != DBNull.Value)
{
parent_id = global.ParseInt(row["parent_id"].ToString());
}
if (row["quantity"] != DBNull.Value)
{
quantity = global.ParseInt(row["quantity"].ToString());
}
Product product = new Product();
product.product_id = global.ParseInt(row["product_id"].ToString());
product.Fetch();
}
}
public void Fetch()
{
StringBuilder query = new StringBuilder();
query.Append("SELECT *, ");
query.Append("(");
query.Append("SELECT thumbnail ");
query.Append("FROM ws_product_file, file ");
query.Append("WHERE file.file_id=ws_product_file.file_id ");
query.Append("AND ws_product_file.product_id=ws_product.product_id ");
query.Append("AND file.status_id=1 ");
query.Append("ORDER BY sortorder DESC LIMIT 0,1");
query.Append(") ");
query.Append("AS thumbnail, ");
query.Append("(");
query.Append("SELECT mimetype ");
query.Append("FROM ws_product_file, file ");
query.Append("WHERE file.file_id=ws_product_file.file_id ");
query.Append("AND ws_product_file.product_id=ws_product.product_id ");
query.Append("AND file.status_id=1 ");
query.Append("ORDER BY sortorder DESC LIMIT 0,1");
query.Append(") ");
query.Append("AS mimetype ");
query.Append("FROM webpage, ws_product ");
query.Append("WHERE webpage.status_id=1 ");
query.Append("AND webpage.webpage_type_id=4 ");
query.Append("AND ws_product.product_id=webpage.webpage_type_content_id ");
query.Append("AND ws_product.product_id=?product_id; ");
database.Query(query.ToString());
database.Add("?product_id", product_id);
foreach (DataRow row in database.FetchAsDataTable().Rows)
{
product_id = global.ParseInt(row["product_id"].ToString());
if (row["parent_id"] != DBNull.Value)
{
parent_id = global.ParseInt(row["parent_id"].ToString());
}
if (row["status_id"] != DBNull.Value)
{
status_id = global.ParseInt(row["status_id"].ToString());
}
if (row["create_date"] != DBNull.Value)
{
create_date = global.ParseDateTime(row["create_date"].ToString());
}
if (row["product_no"] != DBNull.Value)
{
}
}
}
If I run them seperate the result would become:
{Dotcontent.CartProduct}
cart_id: 1
product_id: 64
parent_id: 0
quantity: 2
customer_id: 0
guid: null
{Dotcontent.Product}
webpage_id: 145
website_id: 0
status_id: 1
url: "mode360-composer-fotostudio-fa40"
type: null
webpage_type_id: 0
webpage_type_content_id: 0
version: 0
language_id: 0
parent_id: 0
related_webpage_id: 0
title: "Mode360 Composer Fotostudio FA40"
text: null
short_description: null
meta_description: null
published_from: 1-1-0001
published_to: 1-1-0001
created_on: 1-1-0001
created_by: 0
product_id: 64
create_date: 16-9-2016
product_no: "291610"
ean: ""
price_on_request: False
weight: 0
brand_id: 0
in_export: False
template_id: 1
mimetype: "image/jpeg"
thumbnail: "iVBORw0KGg
price: 0
old_price: 0
label: "Tijdelijke aanbieding"
quantity: 0
CartProduct cart = new CartProduct();
cart.cart_id = 1;
cart.Fetch();
Response.Write("<pre>" + ObjectDumper.Dump(cart) + "</pre>");
Product product = new Product();
product.product_id = cart.product_id;
product.Fetch();
Response.Write("<pre>" + ObjectDumper.Dump(product) + "</pre>");
|
|
|
|
|
Message Removed
modified 4-Nov-16 4:40am.
|
|
|
|
|
I made it but ı have a problem.For example a string aaaabbbccccc like this which compress by RLE first then 4a3b5c compress by huffman and output is .huf binary file,no problem here.But when ı want to decompress .huf file by huffman then aaaabbbccccc but it's wrong which must be 4a3b5c then rle decompress and the our orginal text.Why it is like this ?
|
|
|
|
|
Rıza Berkay Ayçelebi wrote: Why it is like this ? Because you have a problem with your logic in your code. Without any code, that's as close as we can get to an answer I'm afraid.
This space for rent
|
|
|
|
|
Most likely you are passing the original string into your huffman routine, rather than the RLE output.
|
|
|
|
|
If you're using Huffman compression anyway, you might as well use a slightly larger alphabet for the RLE so that lengths and "original symbols" don't overlap.
|
|
|
|
|
I have seen examples of capturing screen shots in win forms .but i don't find any demo on asp.net.
Is there a way we can capture portion of screen using asp.net and c#
|
|
|
|
|
I hope that there are still some security mechanisms preventing that. I do not want any web applications taking screen shots on my computer!
|
|
|
|
|
but it is upto the user who wants take a screen shot!
|
|
|
|
|
The user has a button called "Print Screen". No screen grabbing from a browser.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, Of course.this action is explicit.
|
|
|
|
|
Explicit or no, you can't take a screenshot. You're limited to what the web-browser offers.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You do realise that your C# code runs at the server side don't you? Whatever solution you put in place would require you to use JavaScript.
This space for rent
|
|
|
|
|
this functionality is not achievable in web apps
|
|
|
|
|
And what did you think ASP.NET apps were? Typically, server side apps run on servers with no UI running so you can't exactly take a screenshot of the server.
This space for rent
|
|
|
|
|
feature to take user screen shots by user himself.
like sending an error page to support team.
|
|
|
|
|
You have two choices - find a plugin that screenshot the whole desktop, or limit yourself to capturing the web page[^]. Either way, this is not going to be C#.
This space for rent
|
|
|
|
|
I need to design class library for sql injection prevention by using ASP.NET with C# When the application server received input from the user, it dynamically generated the query based on the input. This query, along with the developer-intended query made use of keyword randomization, where the randomly generated key was appended to the SQL keywords in both queries. These queries were then forwarded to an XML parsing component, which converted both queries into XML trees. and comparing the corresponding nodes in these sub-stacks by using multiple threads, and based on the result of comparison, the algorithm was able to determine whether the dynamically built query was an attack or not. If this query was non-malicious, it was allowed to pass further to the database server for execution. However, if the algorithm determined a query as an attack, it was blocked at the application server and was not sent to the database server for execution. The attack queries were added to an error log to help the system administrators to My Email : [DELETED]@gmail.com
[edit]Email removed - OriginalGriff[/edit]
modified 2-Nov-16 15:46pm.
|
|
|
|