|
With List those lines are valid:
List<string> strs = new List<string>()
{
"helo",
"yes"
};
How to perform the same with Dictionary ?
Dictionary<MyType, string> dict = new Dictionary<MyType, string>()
{
Yes, "yes",
No, "no"
};
Чесноков
|
|
|
|
|
|
that is great thanks
Чесноков
|
|
|
|
|
hey guys..i need some help...i want to connect a MySql database in the other pc...i will develop a program which will be used over the network in the office..i searched something over web and i wrote my codes as i sunderstand from the sites that i searched...but i have such problem when i run the program it gives error like "Unable to connect any of the specified MySql hosts"...i opened 3306 port from the modem..but still i have that problem..here is my codes
try
{
MySqlConnection connect = new MySqlConnection("Data Source=SErver_ip;database=dbname;user id=xxx;password=1");
connect.Open();
Console.WriteLine("Bağlantı Durumu : {0}", connect.State);
connect.Close();
}
catch(exception ex)
{
Console.WriteLine(ex.Message);
}
Where is my mistake??
or any other suggesstion ?
|
|
|
|
|
Too me your connection string doesn't look right compare it too this site and let us know if it works
Connection Strings[^]
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
yeah i compared my connection string with the site one and then i used the same string the one which was suggested by site but still same error...should i make any settings in the server machine?
or do i need mysql in my pc also or just connector is enough ?
|
|
|
|
|
if your using the database name etc as variables then make sure you have concatinated them properly into the string
i.e. "Server=" + ServerName + ";Database="
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
no man..i am not using them as variables...so do u have any other suggestion ?
|
|
|
|
|
erdinc27 wrote: MySqlConnection connect = new MySqlConnection("Data Source=SErver_ip;database=dbname;user id=xxx;password=1");
shoudn't be:
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
beside what qwertz321 told you, you need to check the firewall on a computer that has MySQL installed. For testing purposes you can disable firewall and you will know if firewall is the culprit.
|
|
|
|
|
thanks guys for help..when i installed MySql as a dedicated server my problem is solved...and i unchecked Ip binding...so it works now..
|
|
|
|
|
Is it possible that Dll assembly may have its won icon?
I added it as for ordinary project but it does not show it in windows explorer
Чесноков
|
|
|
|
|
I don't think so. The reason being that icons are usually so users can associate an image with an application. Since DLL's are not applications (they are used by applications), double clicking a DLL isn't going to launch that DLL as an application, so the user has no reason to associate an image with it. Open your System32 folder and you'll notice that not a single DLL has a special icon. You should be able to, however, embed images so that they can be used by other applications (like SHELL32.dll).
|
|
|
|
|
I ran into problem for my school assignment and it is to display whatever in a meal.csv file, here is a code we are starting with. The array string of itemDetails is where the data is store then passed into array ReadLines, then in Main, it is passed to mealContent, but when I tried Console.WriteLine(mealContent); it only prompted System.String[]. So how do I at least display it out in the command prompt. Thanks for the help guys~ Source code is also attached
Code/meal.csv
lunch,bento box b - sashimi,box combo,$9.59
dinner,vegetable sushi,6 rolls,$3.50
dinner,tuna roll,3 rolls,$4.50
dinner,roe, 2 rolls,$3.95
lunch,bento box a - chicken teriyaki,box combo,$8.59
lunch,bento box b - sashimi,box combo,$9.59 dinner,vegetable sushi,6 rolls,$3.50 dinner,tuna roll,3 rolls,$4.50 dinner,roe, 2 rolls,$3.95 lunch,bento box a - chicken teriyaki,box combo,$8.59
FileIOManager/FileLocation.cs
using System;
namespace FileIOManager
{
static class FileLocation
{
public const string INPUT_FILE = "../../Data/meals.csv";
}
}
using System; namespace FileIOManager { static class FileLocation { public const string INPUT_FILE = "../../Data/meals.csv"; } }
FileIOManager/FileReader.cs
using System;
using System.IO;
namespace FileIOManager
{
static public class FileReader
{
private static int GetLineCount()
{
StreamReader sr = new StreamReader(FileLocation.INPUT_FILE);
int counter = 0;
while (!sr.EndOfStream)
{
counter++;
sr.ReadLine();
}
sr.Close();
return counter;
}
public static string[] ReadLines()
{
int totalItems = GetLineCount();
string[] itemDetails = new string[totalItems];
StreamReader sr = new StreamReader(FileLocation.INPUT_FILE);
string itemDetail;
int counter = 0;
while (!sr.EndOfStream){
itemDetail = sr.ReadLine();
if (itemDetail.Trim() != "")
itemDetails[counter++] = itemDetail;
}
sr.Close();
return itemDetails;
}
}
}
|
|
|
|
|
1) Use PRE tags with the lang attribute set to "C#" to format your code better so we have an easier time reading it and helping you.
2) There is no need for those two functions. Just use System.IO.File.ReadAllLines() , which returns an array of strings.
3) To output each item in the array of strings, use a for loop and either Console.WriteLine() or Console.Write() .
4) Instead of using the first function to scan the file to determine the number of lines, just use a List instead of an array. Lists dynamically resize based on how many elements you put in them. Of course, this is assuming that you don't want to use System.IO.File.ReadAllLines() for some reason.
|
|
|
|
|
I figure it out, just iterate over the array and write out each one individually. But im actually stuck on the next step lol i hope you can help out too.
static void Main(string[] args)
{
string[] meals = System.IO.File.ReadAllLines("meals.csv");
foreach (string meal in meals)
Console.WriteLine(meal);
Console.ReadKey();
}
the price actually needed to times by 1.8 so Price = Cost * 1.8
also i'll be dealing with bubble sort.. which I have never learn to knew how to coz we have ot make it look like this in the end
* Lunch Items *
$15.46 bento box a - chicken teriyaki, box combo
$17.26 bento box b – sashimi, box combo
* Dinner Items *
$7.11 roe, 2 rolls
$8.10 tuna roll, 3 rolls
$6.30 vegetable sushi, 6 rolls
|
|
|
|
|
d87c wrote: i hope you can help
I might have, but I will not because you didn't take my advice to use PRE tags. Ignoring my advice clearly shows you aren't considerate of others and would rather have them wade through your poorly formatted code than spend a little time learning how to properly format it. Why should I spend time trying to teach somebody who doesn't want to learn? Also, a bit of advice, use the real words you mean rather than the txt speak versions (e.g., "coz", "ot"). We here appreciate people who realize they have a full keyboard to type with and use that ability. Also, avoiding txt speak will help in the workplace, as using txt speak makes you appear childish and less professional.
|
|
|
|
|
I am new to C# and need to create a new class for NUnit that will enter and test items into an array. The first class is Item
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReneApp.Domain
{
public class Item
{
public string Status;
public string Title;
public string Series;
public string Author;
public string Type;
public string Description;
public bool Addition;
public string status
{
get { return Status; }
set { Status = value; }
}
public string title
{
get { return Title; }
set { Title = value; }
}
public string series
{
get { return Series; }
set { Series = value; }
}
public string author
{
get { return Author; }
set { Author = value; }
}
public string type
{
get { return Type; }
set { Type = value; }
}
public string description
{
get { return Description; }
set { Description = value; }
}
public bool addition
{
get { return Addition; }
set { Addition = value; }
}
}
public delegate void ProcessItemDelegate(Item item);
}
The second class is Transaction
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReneApp.Domain
{
public class Transaction
{
private IList<Item> list = new List<Item>();
public void AddItem(Item item)
{
list.Add(item);
}
public bool ValidateTransaction()
{
if (list == null)
return false;
return true;
}
public void ProcessItem(ProcessItemDelegate processItem)
{
foreach (Item b in list)
{
if (b.addition)
processItem(b);
}
}
}
}
The class that I am testing with is
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReneApp.Domain
{
using NUnit.Framework;
[TestFixture]
public class TransactionTest
{
[Test]
public void ValidateTransaction()
{
Transaction transaction1 = new Transaction("Stock", "Dark Rival", "Masters of Time", "Brenda Joyce", "Book", "Time Travel", true);
Assert.IsTrue(transaction1.ValidateTransaction());
Transaction transaction2 = new Transaction(" ", " ", " ", " ", " ", " ", " ");
Assert.IsTrue(transaction2.ValidateTransaction());
}
}
}
I am unsure how to get the items in the array into the test. Any help would be appreciated. With the current, I am getting an error on the two ValidateTransaction items saying "ReneApp.Domain.Transaction does not contain a constructor that takes 7 arguments"
|
|
|
|
|
mtn*rain wrote: Transaction does not contain a constructor that takes 7 arguments
I suggest you take compiler messages quite literally.
Your Item and Transaction classes don't have explicit constructors (well, you haven't shown any); so all they have is an implicit or default constructor that takes NO arguments.
Furthermore, your 7 parameters suggest they describe a new Item, not a new Transaction. Rethink your structure, add constructors, and check your code carefully.
If you're new to C# (and to object orientation?) you might want and consider something simpler to start with.
|
|
|
|
|
I am entering a new item to test with for NUnit. I am new to this and this is a project required for school, so I cannot do something simpler.
Do you know if I have already listed a constructor in another class that I might use or do I need to completely redo this entire thing?
|
|
|
|
|
How many constructors did you show so far? Have you any idea what a constructor is? Did you pay any attention in class, assuming you were present?
|
|
|
|
|
I don't go to class, I go online. So, yeah, I paid attention to the slides that were sent to me from my professor. I have read several books, done several searches and yes, I am a little lost on exactly how it all works and the answers from my professor are at least better than yours but they are vague.
Thought I could get help here but I guess I will go somewhere else where they realize that not everyone has been doing this for any length of time.
|
|
|
|
|
And you got to learn to walk before you run (dontcha' know)
|
|
|
|
|
Been walking for a while. I know mainframe coding, not much in the way of oop. I understand that what I have coded is incorrect, but I am not sure how and was looking for help in figuring out how to pull from an array in a different class. I would appreciate it if you would hold your comments and hopefully someone else can actually provide what this forum says it will provide.
|
|
|
|
|
1) You don't have any constructors, so the only constructor that exists is the default constructor, which accepts 0 parameters. You are trying to use a constructor with 7 parameters, which doesn't exist.
2) The first constructor you call with the last parameter of type bool, and the second time you call it the parameter is of type string. While it is possible to overload constructors, I doubt this is what you want.
3) You are constructing new instances of type Transaction, though class Item is the one with 7 properties that need to be initialized. I wonder if, perhaps, this is another mistake.
4) You say you are working with an array, yet I don't see any arrays... all I see is a list stored as an IList.
5) As Luc said, it helps to interpret the exceptions, which I'm sure will come more naturally as you work with them more. An excellent source of information is Google (e.g., try Googling for "C# constructor").
6) Inside...
7) Joke.
|
|
|
|
|
Thanks for your reply. I am used to working with Arrays, while it was the List I was talking about. I have done searches looking for some type of examples that have similar lists as what I am using, I am just getting confused with all the different classes and how to access different classes in another class, along with using NUnit.
I will keep looking and probably redo everything I have to see if I can come up with something that does work.
|
|
|
|
|