Lỗi not all code paths return a value c năm 2024
Your method has to return a string regardless of what fashion it is in. If there is no codename you should return Ex: Then in the portion of your code that consumes this method, you need to implement some sort of error handling to say You must have an else condition or a ternary operator in your GetCodeName method. There is no way around it. "Not all code paths return a value" means that inside a function that's supposed to explicitly return something (ie. it's not In this case, this happens if
Thus, the error. To fix this in this case, you want to move the Or you can replace the whole thing with
`void`5 returns -1 if the item isn't found in the array. As Mikael says, this is a pure programming question that doesn't need game-specific expertise, so you can find answers to this elsewhere too.
public static int Nhap(int n) { int[] mang = new int[n]; for (int i = 0; i < n; i++) { Console.Write("nhap phan tu thu {0}", i++); mang[i] = Convert.ToInt32(Console.ReadLine()); } } public static void ThucThi(string[] args) { int n; Console.Write("nhap n: "); n = Convert.ToInt32(Console.ReadLine()); Console.Write(Nhap(n)); } View more random threads:Tạo mảng các button trong C# như thế nào? [Question] Hỏi về hướng Code và Relationship SQL cho một chức năng nhỏ! Gửi 1 phím cho app đang chạy trong lập trình C#? Lỗi khi vào trang web flash game bằng web browser C#? An error occurred creating the form. See Exception.InnerException for details Đổi màu Rows trên Datagridview theo giá trị Vấn đề lấy dữ liệu từ user control. Nhận mail trong vbnet như thế nào? Lấy bảng thông báo từ access lên winform? Không load được designer trong C# -
Bạn đã return đâu. Hàm muốn làm cái gì thì return cái đó. Cuối hàm nhớ thêm return vào cái cần trả về là được -Hàm kiểu int thì làm gì làm, làm xong phải return giá trị cho nó chứ ? Bạn đã return đâu. Hàm muốn làm cái gì thì return cái đó. Cuối hàm nhớ thêm return vào cái cần trả về là được nhưng khi mình return rồi vẫn gặp lỗi bạn ơi, bạn co cách viết nao khác không trích dẫn mình coi với.Tks -
Mã: public static int[] Nhap(int n) { int[] mang = new int[n]; for (int i = 0; i < n; i++) { Console.Write("nhap phan tu thu {0}: ", i); mang[i] = Convert.ToInt32(Console.ReadLine()); } return mang; } public static void Main(string[] args) { int n; Console.Write("nhap n: "); n = Convert.ToInt32(Console.ReadLine()); int []mang = Nhap(n); for (int i = 0; i < n; i++) { Console.Write(mang[i] + " "); } } -
Nếu bạn muốn sử dụng kiểu trả về ở hàm Nhập thì cậu có thể làm theo cách này: Mã: public static int[] Nhap(int n) { int[] mang = new int[n]; for (int i = 0; i < n; i++) { Console.Write("nhap phan tu thu {0}: ", i); mang[i] = Convert.ToInt32(Console.ReadLine()); } return mang; } public static void Main(string[] args) { int n; Console.Write("nhap n: "); n = Convert.ToInt32(Console.ReadLine()); int []mang = Nhap(n); for (int i = 0; i < n; i++) { Console.Write(mang[i] + " "); } } mình đã hiểu vấn đề. Thanks -
public bool Save(ProductDto SanPham) { string strInsert = "insert into Product(productName,Description,URL,groupId) Values("; strInsert += "'" + SanPham.ProductName + "',"; strInsert += "'" + SanPham.Description + "',"; strInsert += "'" + SanPham.Url + "',"; strInsert += "'" + SanPham.GroupId + "',"; } -
của bạn chưa return dữ liệu kìa. khai báo bool thì trả về true or false chứ. oh` hen. thank bạn đã nhắc nhở. hèn gì tìm hoài ko biết chỗ nào. xD --- |